#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, m;
char arr[26][26];
int dp[26][26];
int main() {
  cin.sync_with_stdio(0);
  cin.tie();
  cin.exceptions(cin.failbit);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (i > 1 ? dp[i - 1][j] : 0) + (j > 1 ? dp[i][j - 1] : 0) -
                 ((i > 1 && j > 1) ? dp[i - 1][j - 1] : 0) + (arr[i][j] - '0');
    }
  }
  int ans = 0;
  for (int x1 = 0; x1 <= n; x1++) {
    for (int x2 = x1 + 1; x2 <= n; x2++) {
      for (int y1 = 0; y1 <= m; y1++) {
        for (int y2 = y1 + 1; y2 <= m; y2++) {
          if (dp[x2][y2] - dp[x1][y2] - dp[x2][y1] + dp[x1][y1])
            continue;
          else
            ans = max(ans, 2 * (x2 - x1) + 2 * (y2 - y1));
        }
      }
    }
  }
  cout << ans;
}
