/*
状态转移方程
MAXLEN = max{MAXLEN(area[i-1][j]),MAXLEN(area[i+1][j],MAXLEN(area[i][j+1])),MANLEN(area[i][j-1]) | area[i][j] > ..} + 1
*/
#include"stdio.h"
#include"string.h"
int row,col,area[110][110];
int f[110][110];
int max,i,j;
void in(){
scanf("%d%d",&row,&col);
for(i = 1; i <= row; i++)
for(j = 1; j <= col; j++)
scanf("%d",&area[i][j]);
for(i = 0; i <= col + 1; i++){
area[0][i] = area[row + 1][i] = 0X7FFFF;
}
for(i = 1; i <= row; i++){
area[i][0] = area[i][col + 1] = 0X7FFFF;
}
}
int dp(int x,int y){
int max = -1,temp;
if(f[x][y]) //如果计算过 直接返回
return f[x][y];
int mid = area[x][y];
if(area[x - 1][y] < mid){
temp = dp(x - 1,y) + 1;
if(max < temp)
max = temp;
}
if(area[x + 1][y] < mid){
temp = dp(x + 1,y) + 1;
if(max < temp)
max = temp;
}
if(area[x][y + 1] < mid){
temp = dp(x,y + 1) + 1;
if(max < temp)
max = temp;
}
if(area[x][y - 1] < mid){
temp = dp(x,y - 1) + 1;
if(max < temp)
max = temp;
}
if(max == -1)
return f[i][j] = 1;
return f[i][j] = max;
}
void solve(){
memset(f,0,sizeof(f));
int temp,max = -1;
for(i = 1; i <= row; i++)
for(j = 1; j <= col; j++){
temp = dp(i,j);
if(max < temp)
max = temp;
}
printf("%d\n",max);
}
int main(){
in();
solve();
return 0;
}