#include <bits/stdc++.h>
int maxn(int max, int p) { return max < p ? p : max; }
int main() {
  int n, m, i, j, sum = 0, r, ans, l, k, max = 0, flag;
  char a[30][30];
  int b[30][30] = {0};
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '1') b[i][j] = 1;
      b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
    }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '1') continue;
      for (l = i - 1; l >= 0; l--) {
        for (k = j - 1; k >= 0; k--) {
          int t = b[i][j] - b[l][j] - b[i][k] + b[l][k];
          if (t == 0) max = maxn(max, (i + j - k - l) * 2);
          if (a[i][k] == '1') break;
        }
        if (a[l][j] == '1') break;
      }
    }
  printf("%d\n", max);
  return 0;
}
