#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[27][27], c[27][27], i, j, p = 0;
  cin >> n >> m;
  char t;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) {
      a[i][j] = 0;
      c[i][j] = 0;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> t;
      if (t == '1') {
        a[i][j] = 1;
      }
      c[i][j] = c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] + a[i][j];
    }
  }
  int x1, x2, y1, y2;
  for (x1 = 1; x1 <= n; x1++)
    for (y1 = 1; y1 <= m; y1++)
      for (x2 = x1; x2 <= n; x2++)
        for (y2 = y1; y2 <= m; y2++)
          if (c[x2][y2] - c[x1 - 1][y2] - c[x2][y1 - 1] + c[x1 - 1][y1 - 1] ==
              0)
            p = max(p, x2 - x1 + y2 - y1 + 2);
  cout << p * 2;
  return 0;
}
