//Nông Dân John | THPT Nguyễn Quang Diêu
Var N,M: Integer;
A: Array[0..1000,0..1000] of byte;
F: Array[0..1000,0..1000] of integer;
Procedure Enter;
var i,j: Integer;
begin
Readln(M,N);
For i:=1 to M do
begin
for j:=1 to N do read(A[i,j]);
readln
end;
Fillchar(F, sizeof(F), 0);
end;
Function max(x,y,z: Integer): integer;
begin
max:=x;
if y<max then max:=y;
if z<max then max:=z;
end;
Procedure Process;
var i,j: integer;
begin
For i:=1 to M do
For j:=1 to N do
if (A[i,j]=A[i-1,j])and(A[i,j]=A[i,j-1])and(A[i,j]=A[i-1,j-1]) then
F[i,j]:=max(F[i-1,j],F[i,j-1],F[i-1,j-1])+1 else F[i,j]:=1;
end;
Procedure Print;
var i,max,j: Integer;
begin
max:=F[1,1];
for i:=1 to m do
for j:=1 to n do
if F[i,j]>max then max:=F[i,j];
Write(max);
end;
Begin
Assign(input, ''); reset(input);
Assign(output, ''); rewrite(output);
Enter;
Process;
Print;
Close(input);
Close(output)
End.
Ly9Ow7RuZyBEw6JuIEpvaG4gfCBUSFBUIE5ndXnhu4VuIFF1YW5nIERpw6p1CgpWYXIgTixNOiBJbnRlZ2VyOwogICAgQTogQXJyYXlbMC4uMTAwMCwwLi4xMDAwXSBvZiBieXRlOwogICAgRjogQXJyYXlbMC4uMTAwMCwwLi4xMDAwXSBvZiBpbnRlZ2VyOwpQcm9jZWR1cmUgRW50ZXI7CnZhciBpLGo6IEludGVnZXI7CmJlZ2luCiAgICBSZWFkbG4oTSxOKTsKICAgIEZvciBpOj0xIHRvIE0gZG8KICAgICAgYmVnaW4KICAgICAgICBmb3Igajo9MSB0byBOIGRvIHJlYWQoQVtpLGpdKTsKICAgICAgICByZWFkbG4KICAgICAgZW5kOwogICAgRmlsbGNoYXIoRiwgc2l6ZW9mKEYpLCAwKTsKZW5kOwpGdW5jdGlvbiBtYXgoeCx5LHo6IEludGVnZXIpOiBpbnRlZ2VyOwpiZWdpbgogICAgbWF4Oj14OwogICAgaWYgeT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