#include <bits/stdc++.h>
using namespace std;
string x[45];
int dp[45][45];
int row[45][45];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
    x[i] = '0' + x[i];
    int pre = 0;
    for (int j = 1; j <= m; ++j) {
      if (x[i][j] == '1') pre = j;
      row[i][j] = pre;
    }
  }
  for (int k = 1; k <= n; ++k) {
    for (int l = 1; l <= m; ++l) {
      dp[k][l] = max(dp[k - 1][l], dp[k][l - 1]);
      if (x[k][l] == '1') continue;
      int s = 0, minn = m;
      for (int g = k; g >= 1; --g) {
        if (x[g][l] == '1') break;
        minn = min(minn, l - row[g][l]);
        dp[k][l] = max(dp[k][l], minn + (k - g + 1));
      }
    }
  }
  cout << dp[n][m] * 2 << endl;
}
