#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int INF = 3e16;
const int N = 1e3 + 7;
const int mod = 1e9 + 7;
int maxn, minn;
int T, n, m, q;
char mp[N][N];
int arr[N][N];
int dp[N][N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      arr[i][j] = mp[i][j] - '0';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + arr[i][j];
    }
  }
  maxn = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 0; k < i; k++) {
        for (int l = 0; l < j; l++) {
          int ans = dp[i][j] - dp[i][l] - dp[k][j] + dp[k][l];
          if (ans == 0) {
            int a = i - k;
            int b = j - l;
            maxn = max(maxn, 2 * a + 2 * b);
          }
        }
      }
    }
  }
  cout << maxn << endl;
  return 0;
}
