#include
#include
#include
using namespace std;
#define maxn 105
int r,c;
int data[maxn][maxn],len[maxn][maxn];
const int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int dp(int x,int y){
if(len[x][y]!=0)
return len[x][y];
int m = 0;
for(int k=0;k<4;k++){
int px = x+dx[k];
int py = y+dy[k];
if(px<0||px>=r||py<0||py>=c)continue;
if(data[px][py]<data[x][y]){
m = max(m,dp(px,py));
}
}
len[x][y] = m+1;
return len[x][y];
}
int main(){
scanf("%d%d",&r,&c);
for(int i=0;i){
for(int j=0;j){
scanf("%d",&data[i][j]);
}
}
memset(len,0,sizeof(len));
for(int i=0;i){
for(int j=0;j){
dp(i,j);
}
}
int len_max = 0;
for(int i=0;i){
for(int j=0;j){
len_max = max(len_max,len[i][j]);
}
}
printf("%d\n",len_max);
return 0;
}