program _________d;
 var
     f:text;
     i,j,k,M,N,ii,jj,ii1,jj1,i1,j1:longint;
     a,b: array[1..51,1..51] of longint;
     c: array[1..51,1..51] of byte;
     all,first,second,ans,firsts,seconds,alls: longint;
  procedure krasim(x,y,n: longint);
  var i,j: integer;
  begin
    i:=x; j:=y;
    while (a[i,j]<>1) and (i in [1..n]) and (j in [1..m]) do begin
      b[i,j]:=n;
      inc(i);
    end;
    while (a[i,j]<>1) and (i in [1..n]) and (j in [1..m]) do begin
      b[i,j]:=n;
      dec(i);
    end;
    while (a[i,j]<>1) and (i in [1..n]) and (j in [1..m]) do begin
      b[i,j]:=n;
      inc(j);
    end;
    while (a[i,j]<>1) and (i in [1..n]) and (j in [1..m]) do begin
      b[i,j]:=n;
      dec(j);
    end;
  end;
  function tryrect(x1,y1,x2,y2: longint): longint;
  var i,j: integer;

  begin
     ans:=0;
    for i:=x1 to x2 do
      if ans<>-1 then
      for j:=y1 to y2 do begin
        if (a[i,j]<>0) and (a[i,j]=2) then begin if (c[i,j]=0) then begin ans:=ans+1; c[i,j]:=1 end; end else begin  ans:=-1; break; end;
      end;
    if ans>0 then begin
      tryrect:=abs(x1-x2)*abs(y1-y2);

    end else tryrect:=-1;
  end;
 begin
   assign(f,'input.txt');
   reset(f);
   read(f,n,m);
   for i:=1 to n do
     for j:=1 to m do
      read(f,a[i,j]);

   close(f);
   all:=0;
   for i:=1 to n do
     for j:=1 to m do begin
       if a[i,j]=2 then begin krasim(i,j,3); inc(all); end;
     end;
   alls:=-1;

   for i:=1 to n do begin
    for j:=1 to m do begin
      if b[i,j]=3 then begin
        for ii:=i to n do begin
          for jj:=j to n do begin
           if a[ii,jj]=1 then continue;
           fillchar(c,sizeof(c),0);
           firsts:=tryrect(i,j,ii,jj);
           if firsts=-1 then continue;
           first:=ans;
           for i1:=1 to n do
             for j1:=1 to n do
              if b[i1,j1]=3 then begin
                for ii1:=i1 to n do begin
                  for jj1:=j1 to n do begin
                    if a[ii1,jj1]=1 then continue;
                      seconds:=tryrect(i1,j1,ii1,jj1);
                      if seconds=-1 then continue;
                      second:=ans;
                      if second+first=all then begin
                        if alls<seconds+firsts then alls:=seconds+firsts;
                      end;
                  end;
                end;

              end;

          end;
        end;
      end;
    end;
   end;

   assign(f,'output.txt');
   rewrite(f);
    write(f,alls);
   close(f);
 end.
