program fish_eating;
var i,j,k,n,m,max,ans,sum:integer;
a,b:array[0..2501,0..2501]of integer;
begin readln(n,m);
fillchar(a,sizeof(a),0);
b:=a;
for i:=1 to n do
for j:=1 to m do read(a[i,j]);
b:=a;
for i:=1 to n do
for j:=1 to m do
if a[i,j]=1 then a[i,j]:=a[i,j]+a[i-1,j-1];
for i:=1 to n do
for j:=1 to m do
if b[i,j]=1 then b[i,j]:=b[i,j]+b[i+1,j+1];
max:=0;
for i:=1 to n do
for j:=1 to m do
if (a[i,j]>max)and((a[i+1,j+1]=0)or(a[i-a[i,j],j-a[i,j]]=0)) then max:=a[i,j];
writeln(max);
end.