#include<iostream>
using namespace std;
int r,c;
int a[101][101]={0},d[101][101];
int max(int a,int b,int c,int d)
{
int t1,t2;
if(a>b)t1=a;
else t1=b;
if(c>d) t2=c;
else t2=d;
if(t1>t2) return t1;
else return t2;
}
int f(int n,int m,int h)
{
if(a[n][m]==0||h<=a[n][m])
return 0;
if(d[n][m]>=0)
return d[n][m];
d[n][m]=max(f(n-1,m,a[n][m]),f(n,m-1,a[n][m]),f(n+1,m,a[n][m]),f(n,m+1,a[n][m]))+1;
return d[n][m];
}
int main()
{
int i,j;
cin>>r>>c;
int m=0;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cin>>a[i][j];
d[i][j]=-1;
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
d[i][j]=f(i,j,10000);
if(d[i][j]>m)
m=d[i][j];
}
}
cout<<m<<endl;
return 0;
}