#include <bits/stdc++.h>
using namespace std;
int n, m;
int mas[50][50];
int sum[50][50];
int fun(int a, int b, int c, int d) {
  return 2 * (c - a + 1) + 2 * (d - b + 1);
}
int f(int x, int y) {
  int res = 0;
  int s3 = 0;
  if (x > 0 && y > 0) s3 = sum[x - 1][y - 1];
  for (int i = x; i < n; i++)
    for (int j = y; j < m; j++) {
      int s1 = 0, s2 = 0;
      if (y > 0) s1 = sum[i][y - 1];
      if (x > 0) s2 = sum[x - 1][j];
      if (sum[i][j] == (s1 + s2 - s3)) {
        int d = fun(x, y, i, j);
        res = max(res, d);
      }
    }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;
      mas[i][j] = c - '0';
    }
  int ans = 0;
  sum[0][0] = mas[0][0];
  for (int i = 1; i < n; i++) sum[i][0] = sum[i - 1][0] + mas[i][0];
  for (int i = 1; i < m; i++) sum[0][i] = sum[0][i - 1] + mas[0][i];
  for (int i = 1; i < n; i++)
    for (int j = 1; j < m; j++) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mas[i][j];
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (mas[i][j] == false) {
        int p = f(i, j);
        ans = max(ans, p);
      }
  cout << ans << endl;
  return 0;
}
