#include<iostream>
using namespace std;
int r,c,a[100][100],s[100][100];
int b[100][100];
int pos[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
bool check(int xnow,int ynow,int tox,int toy){
if(tox>=0&&tox<=r&&toy>=0&&toy<=c&&b[tox][toy]==0&&a[tox][toy]<a[xnow][ynow]) return true;
return false;
}
int dfs(int x,int y){
if(s[x][y]) return s[x][y];
s[x][y] = 1;
for(int q = 0;q<4;q++){
int xnext = x+pos[q][0];
int ynext = y+pos[q][1];
if(check(x,y,xnext,ynext)){
b[xnext][ynext] = 1;
dfs(xnext,ynext);
b[xnext][ynext] = 0;
s[x][y] = max(s[x][y],s[xnext][ynext]+1);
}
}
return s[x][y];
}
int main(){
cin>>r>>c;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
cin>>a[i][j];
}
}
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
b[i][j] = 1;
dfs(i,j);
b[i][j] = 0;
}
}
int maxn = 1;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
if(s[i][j] > maxn){
maxn = s[i][j];
}
}
}
cout<<maxn;
return 0;
}