#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int row,col;
int height[100][100];
//存放每个点的结果
int length[100][100];
int dp(int i,int j)
{
int max = 0;
int temp;
if(length[i][j] > 0 )
return length[i][j];
if(j-1 >= 0) {
if( height[i][j] > height[i][j-1] ) {
temp = dp(i,j-1);
if ( max < temp)
max = temp;
}
}
if(i-1 >=0) {
if(height[i][j] > height[i-1][j] ) {
temp = dp(i-1,j);
if(max < temp)
max = temp;
}
}
if(j+1 < col) {
if (height[i][j] > height[j][j+1] ) {
temp = dp(i,j+1);
if(max < temp)
max = temp;
}
}
if(i+1 < row) {
if(height[i][j] > height[i+1][j] ) {
temp = dp(i+1,j);
if (max < temp)
max = temp;
}
}
length[i][j] = max + 1;
return length[i][j];
}
int main(void)
{
int i,j;
int max = -1;
scanf("%d %d",&row,&col);
memset(length,0,sizeof(length));
for( i = 0;i<row;i++) {
for (j =0;j<col;j++) {
scanf("%d",&height[i][j]);
//printf("%d ",height[i][j]);
}
}
for( i = 0; i < row;i++) {
for(j=0; j < col; j++) {
max = dp(i,j);
}
}
max = length[0][0];
for ( i = 0;i<row;i++) {
for(j=0;j<col;j++) {
if(length[i][j] > max)
max = length[i][j];
}
}
printf("%d\n",max);
//system("pause");
return 0;
}