#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (int i = 0; i < int(n); ++i) cin >> v[i];
  vector<vector<int> > S(n, vector<int>(m, 0));
  for (int i = 0; i < int(n); ++i) {
    int ac = 0;
    for (int j = 0; j < int(m); ++j) {
      if (v[i][j] == '1') ++ac;
      if (i > 0) S[i][j] = S[i - 1][j];
      S[i][j] += ac;
    }
  }
  int ans = 0;
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j)
      for (int a = 0; a < int(n); ++a)
        for (int b = 0; b < int(m); ++b)
          if (i <= a and j <= b) {
            int sum = S[a][b];
            if (i > 0) sum -= S[i - 1][b];
            if (j > 0) sum -= S[a][j - 1];
            if (i > 0 and j > 0) sum += S[i - 1][j - 1];
            if (sum == 0) ans = max(ans, a + a - i - i + b + b - j - j + 4);
          }
  cout << ans << endl;
}
