#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string inp[n];
  for (int i = 0; i < n; i++) cin >> inp[i];
  int ans = 4;
  for (int x1 = 0; x1 < n; x1++) {
    for (int x2 = x1; x2 < n; x2++) {
      for (int y1 = 0; y1 < m; y1++) {
        for (int y2 = y1; y2 < m; y2++) {
          int i;
          for (i = x1; i <= x2; i++) {
            int j;
            for (j = y1; j <= y2; j++)
              if (inp[i][j] == '1') break;
            if (j <= y2) break;
          }
          if (i > x2) {
            int p = 2 * (x2 + y2 - x1 - y1 + 2);
            ans = max(ans, p);
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
