#include <bits/stdc++.h>
using namespace std;
int n, m, far[26][26];
char g[26][26];
bool dp[26][26][26][26];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> g[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--) {
      if (g[i][j] == '1')
        far[i][j] = j - 1;
      else if (j == m)
        far[i][j] = j;
      else
        far[i][j] = far[i][j + 1];
    }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int dist = 1 << 20;
      for (int r2 = i; r2 <= n && g[r2][j] == '0'; r2++) {
        dist = min(dist, far[r2][j]);
        ans = max(ans, 2 * (r2 - i + 1 + dist - j + 1));
      }
    }
  cout << ans;
}
