#include
void num(int x,int y);
int max(int c,int d);
int a[100][100],b[100][100];
void main()
{
int r,c,i,j,n;
scanf("%d %d",&r,&c);//r代表行数,c代表列数
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
{
a[i][j]=-1;b[i][j]=1;
}
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&a[i][j]);//高度
num(1,1);n=0;
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
n=max(n,b[i][j]);
printf("%d",n);
system("pause");
}
int max(int c,int d)
{
if(c>d) return c;
else return d;
}
void num(int x,int y)
{
if(a[x+1][y]!=-1&&a[x+1][y] {
b[x+1][y]==1?
b[x][y]=num(x+1,y):(b[x][y])=max(b[x+1][y],b[x][y]);
}
if(a[x-1][y]!=-1&&a[x-1][y] {
b[x-1][y]==1?
b[x][y]=num(x-1,y):(b[x][y])=max(b[x-1][y]+1,b[x][y]);
}
if(a[x][y+1]!=-1&&a[x][y+1] {
b[x][y+1]==1?
b[x][y+1]=num(x,y+1):(b[x][y])=max(b[x][y+1]+1,b[x][y]);
}
if(a[x][y-1]!=-1&&a[x][y-1] {
b[x][y-1]==1?
b[x][y-1]=num(x,y-1):(b[x][y])=max(b[x][y-1]+1,b[x][y]);
}
}//运行不了,怎么解决