var n, m : longint;
    tab, left, up, before, new : array[0..3000, 0..3000] of int64;
    bool : array[1..3000, 1..3000] of boolean;
    i, j : longint;
    s : string;
    mx : int64;

function check(x, y : longint) : boolean;
begin
  if (tab[x][y] = tab[x-1][y]) and (tab[x][y] = tab[x][y-1]) and (tab[x][y] = tab[x-1][y-1]) then
    check := True
  else
    check := False;
end;

begin
  assign(input, 'video.in');  assign(output, 'video.out');
//  assign(input, 'input.txt');  assign(output, 'output.txt');
  reset(input); rewrite(output);

  readln(n, m);

  for i := 1 to n do
  begin
    readln(s);
    for j := 1 to m do
    begin
      tab[i][j] := ord(s[j]) - ord('0');
      tab[i + n][j] := tab[i][j];
      tab[i][j + m] := tab[i][j];
      tab[i + n][j + m] := tab[i][j];
    end;
  end;

  for i := 2 to n*2 do
    for j := 2 to m*2 do
      bool[i][j] := check(i, j);

  for i := 1 to 3000 do
  begin
    left[i][1] := 0;
    up[1][i] := 0;
    before[i][1] := 0;
    before[1][i] := 0;
  end;

  for i := 1 to n*2 do
    for j := 2 to m*2 do
      if bool[i][j] then
        left[i][j] := left[i][j-1] + 1
      else
        left[i][j] := left[i][j-1];

  for j := 1 to m*2 do
    for i := 2 to n*2 do
      if bool[i][j] then
        up[i][j] := up[i-1][j] + 1
      else
        up[i][j] := up[i-1][j];

  for i := 2 to n*2 do
    for j := 2 to m*2 do
    begin
      before[i][j] := before[i-1][j-1] + left[i][j] + up[i][j];
      if bool[i][j] then
        dec(before[i][j]);
    end;

  for i := n to n*2 do
    for j := m to m*2 do
      new[i][j] := before[i][j] + before[i-n+1][j-m+1] - before[i-n+1][j] - before[i][j-m+1];

  mx := 0;
  for i := n to n*2 do
    for j := m to m*2 do
      if new[i][j] > mx then
        mx := new[i][j];

  writeln(mx);
end.
