#include <bits/stdc++.h>
using namespace std;
void yes(bool fl = true) {
  if (fl)
    cout << "YES\n";
  else
    cout << "Yes\n";
}
void no(bool fl = true) {
  if (fl)
    cout << "NO\n";
  else
    cout << "No\n";
}
long long a, b, c, d, e, f, g, n, m, k, t, x, h, w, p, q, y;
string str = "";
long long mod = 1e9 + 7;
int grid[30][30];
int dp[30][30];
void solve() {
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    cin >> str;
    for (int j = 1; j < m + 1; j++) {
      if (str[j - 1] == '0') grid[i][j] = 1;
    }
  }
  dp[1][1] = grid[1][1];
  for (int i = 2; i <= m; i++) dp[1][i] = dp[1][i - 1] + grid[1][i];
  for (int i = 2; i <= n; i++) dp[i][1] = dp[i - 1][1] + grid[i][1];
  for (int i = 2; i <= n; i++) {
    for (int j = 2; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + grid[i][j] - dp[i - 1][j - 1];
    }
  }
  int maxP = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int y = i; y <= n; y++) {
        for (x = j; x <= m; x++) {
          int S = dp[y][x] + dp[i - 1][j - 1] - dp[y][j - 1] - dp[i - 1][x];
          int wid = x - j + 1;
          int hei = y - i + 1;
          if (S == wid * hei) {
            maxP = max(maxP, 2 * (hei + wid));
          }
        }
      }
    }
  }
  cout << maxP << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int cases = 1;
  while (cases--) {
    solve();
  }
  return 0;
}
