#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 305;
int a[maxn][maxn];
int f[maxn][maxn];
int r,c;
int dx[4] = {-1,0,0,1};
int dy[4] = {0,1,-1,0};
/*
f[i][j]:
从点(i,j)出发的路径长度max
*/
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 xx = x + dx[i];
int yy = y + dy[i];
if(xx>=1 and xx<=r and yy>=1 and yy<=c)
{
if(a[x][y] > a[xx][yy]) {
f[x][y] = max(f[x][y] , dp(xx,yy) + 1);
}
}
}
return f[x][y];
}
int main()
{
cin >> r >> c;
for(int i=1;i<=r;i++) {
for(int j=1;j<=c;j++) {
cin >> a[i][j];
}
}
memset(f,-1,sizeof f);
int res = 0;
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
res = max(res,dp(i,j));
}
}
cout << res <<endl;
return 0;
}