#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
using namespace std;
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(a) (int) (a).size()
#define endl "\n"
const int N=200;
int g[N][N];
int r,c;
int f[N][N];
int dfs(int x,int y){
if(x>r-1||x<0||y>c-1||y<0) return 0;
if(f[x][y]!=-1) return f[x][y];
int ans=0;
if(g[x][y]>g[x][y+1]) ans=max(ans,dfs(x,y+1));
if(g[x][y]>g[x+1][y]) ans=max(ans,dfs(x+1,y));
if(g[x][y]>g[x-1][y]) ans=max(ans,dfs(x-1,y));
if(g[x][y]>g[x][y-1]) ans=max(ans,dfs(x,y-1));
return f[x][y]=ans+1;
}
void solved() {
cin>>r>>c;
int ans=0;
memset(f,-1,sizeof f);
for(int i=0;i<r;i++){
for(int j=0;j<c;j++) cin>>g[i][j];
}
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
ans=max(ans,dfs(i,j));
}
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solved();
return 0;
}