#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 310;
int r, c;
int f[N][N], a[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int dp(int x, int y)
{
if (f[x][y] != -1) return f[x][y];
f[x][y] = 1; // 务必注意初始化,只走当前这格
for (int i = 0; i < 4; i ++)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx >= 1 && nx <= r && ny >= 1 && ny <= c && a[nx][ny] < a[x][y])
{
f[x][y] = max(f[x][y], dp(nx, ny) + 1);
}
}
return f[x][y];
}
int main()
{
scanf("%d%d", &r, &c);
int res = 0;
for (int i = 1; i <= r; i ++)
{
for (int j = 1; j <= c; j ++)
scanf("%d", &a[i][j]);
}
memset(f, -1, sizeof f);
for (int i = 1; i <= r; i ++)
{
for (int j = 1; j <= c; j ++)
res = max(res, dp(i, j));
}
printf("%d\n", res);
return 0;
}