#include <iostream>
#include <cstring>
using namespace std;
const int N = 310;
int f[N][N];
int a[N][N];
int n,m;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int dfs(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 xx = x + dx[i] ,yy = y + dy[i];
if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[x][y] > a[xx][yy] )
{
f[x][y] = max(f[x][y] , dfs(xx,yy)+ 1) ;
}
}
return f[x][y];
}
int main()
{
cin >> n >> m;
for (int i = 1;i <= n;i ++ )
for (int j = 1;j <= m;j ++ )
cin >> a[i][j];
int ans = 0;
memset(f,-1,sizeof f);
for (int i = 1;i <= n;i ++ )
for (int j = 1;j <= m;j ++)
ans = max(ans,dfs(i, j));
cout << ans << endl;
return 0;
}