#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = ({
    int x;
    scanf("%d", &x);
    x;
  }),
      m = ({
        int x;
        scanf("%d", &x);
        x;
      }),
      r = 0, i, j, k;
  char sa[33];
  int sum[33][33];
  for (i = 1; i <= n; i++) {
    scanf(" %s", sa);
    for (j = 1; j <= m; j++) {
      sum[i][j] = sa[j - 1] - '0';
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
  for (int x1 = 1; x1 <= n; x1++)
    for (int y1 = 1; y1 <= m; y1++)
      for (int x2 = x1; x2 <= n; x2++)
        for (int y2 = y1; y2 <= m; y2++) {
          int s = sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] +
                  sum[x1 - 1][y1 - 1];
          if (s == 0) r = max(r, 2 * (x2 - x1 + 1 + y2 - y1 + 1));
        }
  printf("%d\n", r);
  return 0;
}
