#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int N = 1000;
int n, k, m;
string s[N];
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  int res = 4;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      for (int d = 1; d <= m; d++)
        for (int h = 1; h <= n; h++) {
          int ok = 1;
          for (int x = i; x <= min(n, i + h) - 1; x++)
            for (int y = j; y <= min(m, j + d) - 1; y++)
              if (s[x][y] == '1') ok = 0;
          if (ok)
            res = max(res, 2 * (min(n, i + h) - i) + 2 * (min(m, j + d) - j));
        }
    }
  cout << res;
  return 0;
}
