#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long cmp(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second;
}
int main() {
  int n, m;
  cin >> n >> m;
  char a[n + 1][m + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  long long ans = 0;
  long long x[n + 1][m + 1];
  long long y[n + 1][m + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      x[i][j] = 0;
      y[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '0') {
        x[i][j] = x[i][j - 1] + 1;
        y[i][j] = y[i - 1][j] + 1;
        long long ymin = y[i][j];
        long long xmin = x[i][j];
        for (int k = j - x[i][j] + 1; k <= j; k++) {
          ymin = min(ymin, y[i][k]);
        }
        for (int k = i - y[i][j] + 1; k <= i; k++) {
          xmin = min(xmin, x[k][j]);
        }
        long long p1 = ymin + x[i][j];
        long long p2 = xmin + y[i][j];
        long long p = (max(p1, p2)) * 2;
        ans = max(p, ans);
      }
    }
  }
  cout << ans << endl;
}
