#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (int i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  vector<vector<int> > sum(n, vector<int>(m, 0));
  if (a[0][0] == '1') sum[0][0] = 1;
  for (int i = (1); i < (m); ++i) sum[0][i] = sum[0][i - 1] + (a[0][i] - '0');
  for (int i = (1); i < (n); ++i) sum[i][0] = sum[i - 1][0] + (a[i][0] - '0');
  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] + (a[i][j] - '0');
    }
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j) {
      for (int i2 = (i); i2 < (n); ++i2) {
        for (int j2 = (j); j2 < (m); ++j2) {
          int sm = sum[i2][j2] - (i == 0 ? 0 : sum[i - 1][j2]) -
                   (j == 0 ? 0 : sum[i2][j - 1]) +
                   (i * j == 0 ? 0 : sum[i - 1][j - 1]);
          if (!sm) {
            ans = max(ans, 2 * ((i2 - i + 1) + (j2 - j + 1)));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
