#include <bits/stdc++.h>
using namespace std;
int r,c,h[300][300],s[300][300],ans;
int search(int x,int y)
{
if(s[x][y])
return s[x][y];
s[x][y]++;
int pd[10]={0};
if(y>1&&h[x][y-1]<h[x][y])
pd[1]+=search(x,y-1);
if(x<c&&h[x+1][y]<h[x][y])
pd[2]+=search(x+1,y);
if(y<r&&h[x][y+1]<h[x][y])
pd[3]+=search(x,y+1);
if(x>1&&h[x-1][y]<h[x][y])
pd[4]+=search(x-1,y);
sort(pd+1,pd+5);
s[x][y]+=pd[4];
return s[x][y];
}
int main()
{
cin>>r>>c;
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
scanf("%d",&h[i][j]);
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
ans=max(ans,search(i,j));
cout<<ans;
return 0;
}