#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  while (cin >> n) {
    cin >> m;
    vector<vector<int> > A(n, vector<int>(m, 0));
    vector<string> S(n);
    cin >> S[0];
    A[0][0] = (S[0][0] - '0');
    for (int j = 1; j < m; ++j) {
      A[0][j] = (S[0][j] - '0') + A[0][j - 1];
    }
    for (int i = 1; i < n; ++i) {
      cin >> S[i];
      A[i][0] = (S[i][0] - '0') + A[i - 1][0];
      for (int j = 1; j < m; ++j) {
        A[i][j] = (S[i][j] - '0') + A[i][j - 1] + A[i - 1][j] - A[i - 1][j - 1];
      }
    }
    int result = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (S[i][j] == '0') {
          for (int k = i; k < n; ++k) {
            for (int l = j; l < m; ++l) {
              int nb = A[k][l];
              if (i > 0) nb -= A[i - 1][l];
              if (j > 0) nb -= A[k][j - 1];
              if (i > 0 && j > 0) nb += A[i - 1][j - 1];
              if (nb == 0) {
                result = max((k - i + l - j + 2) * 2, result);
              }
            }
          }
        }
      }
    }
    cout << result << endl;
  }
  return 0;
}
