#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, x1, x2, y1, y2, t, flag, maxn, c;
  char a[30][30];
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", a[i]);
  maxn = 0;
  for (x1 = 0; x1 < n; x1++) {
    for (y1 = 0; y1 < m; y1++) {
      flag = 1;
      for (x2 = x1; x2 < n; x2++) {
        for (y2 = y1; y2 < m; y2++) {
          if (a[x2][y2] == '1') {
            flag = 0;
            break;
          }
          c = ((abs(x1 - x2) + 1) + (abs(y1 - y2) + 1)) * 2;
          if (c > maxn) maxn = c;
        }
        if (flag == 0) break;
      }
      flag = 1;
      for (y2 = y1; y2 < m; y2++) {
        for (x2 = x1; x2 < n; x2++) {
          if (a[x2][y2] == '1') {
            flag = 0;
            break;
          }
          c = ((abs(x1 - x2) + 1) + (abs(y1 - y2) + 1)) * 2;
          if (c > maxn) maxn = c;
        }
        if (flag == 0) break;
      }
    }
  }
  printf("%d\n", maxn);
}
