#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > cum(n + 1, vector<int>(m + 1, 0));
  char x;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> x;
      int c = (x == '1');
      cum[i][j] = cum[i][j - 1] + cum[i - 1][j] + c - cum[i - 1][j - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      for (int ii = i; ii <= n; ++ii) {
        for (int jj = j; jj <= m; ++jj) {
          int aa = cum[ii][j - 1] + cum[i - 1][jj] - cum[i - 1][j - 1];
          aa = cum[ii][jj] - aa;
          if (aa != 0) break;
          int r = (ii - i) + 1, cl = (jj - j) + 1;
          int s = 2 * r + 2 * cl;
          ans = max(ans, s);
        }
      }
    }
  }
  cout << ans << endl;
}
