program zadd;
uses math;
{$APPTYPE CONSOLE}

var inf,outf:text;
 n,m,i,k,j:integer;
 mm:array[1..50,1..50] of integer;
 left1,up1,down1,right1:Integer;
 left2,up2,down2,right2:Integer;
 yes:Boolean;
begin
assign(inf,'Input.txt');
assign(outf,'Output.txt');
reset(inf);
rewrite(outf);
 read(inf,n,m);
 left1:=500;
 right1:=500;
 up1:=100;
 down1:=-500;
 left2:=-500;
 right2:=-500;
 up2:=100;
 down2:=-500;
 for i:=1 to n do
 for j:=1 to m do
 begin
        read(inf,mm[i,j]);
        if (mm[i,j]=2) then begin
        if left1>j left1:=j;
{        if left2>j then left2:=j;}
        if up1>i then up1:=i;
{        if up2>i then up2:=i;}
        if right2<j right2:=j;
{        if right1<j then right1:=j;}
        if down2>i then down2:=i;
{        if down1<0 then down1:=i;}
        end;
 end;
 for i:=up1 to down2 do
 for j:=left1 to right2 do
 begin
        if (mm[i,j]=1) and (right1>j) then right1:=j;
        if (mm[i,j]=1) and (left2<j) then left2:=j;
        if (mm[i,j]=1) and (up2>i) then up2:=i;
        if (mm[i,j]=1) and (down1<i) then down1:=i;
 end;
        yes:=false;
 for i:=up1 to down2 do
 for j:=left1 to right2 do
 begin
  if (mm[i,j]=2) and (i>right1) and (j<up2) then
  begin
  end;
 end;


close(inf);
close(outf);
end.
