#include <bits/stdc++.h>
using namespace std;
int n, m, ans, f[30][30];
char mp[30][30];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      f[i][j] = f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1];
      if (mp[i - 1][j - 1] == '1') f[i][j]++;
    }
  ans = 0;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++)
      for (int xx = x; xx <= n; xx++)
        for (int yy = y; yy <= m; yy++)
          if (f[xx][yy] - f[x - 1][yy] - f[xx][y - 1] + f[x - 1][y - 1] == 0 &&
              (2 * (xx - x + yy - y + 2) > ans))
            ans = 2 * (xx - x + yy - y + 2);
  printf("%d\n", ans);
  return 0;
}
