#include<iostream>
#include<queue>
using namespace std;
short int r,c;
struct sb{
short int x,y;
};
short int fl[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
short int a[102][102];
bool f[102][102];
short int len[102][102];
short int lans=-1;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>r>>c;
for(short int i=1;i<=r;i++){
for(short int j=1;j<=c;j++){
cin>>a[i][j];
}
}
for(short int i=1;i<=r;i++){
for(short int j=1;j<=c;j++){
queue<sb>q;
sb temp;
temp.x=i;
temp.y=j;
q.push(temp);
len[i][j]=1;
while(!q.empty()){
sb rr=q.front();
q.pop();
for(short int t=0;t<4;t++){
sb x1;
x1.x=rr.x+fl[t][0];
x1.y=rr.y+fl[t][1];
if(a[x1.x][x1.y]<a[rr.x][rr.y]&&(x1.x>=1&&x1.x<=r)&&(x1.y>=1&&x1.y<=c)&&f[x1.x][x1.y]==false){
f[x1.x][x1.y]==true;
q.push(x1);
len[x1.x][x1.y]=len[rr.x][rr.y]+1;
}
}
}
short int ans=-1;
for(short int k=1;k<=r;k++){
for(short int y=1;y<=c;y++){
ans=max(ans,len[k][y]);
}
}
lans=max(lans,ans);
}
}
cout<<lans;
return 0;
}