#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int dp[n][m][n][m];
  for (int i1 = 0; i1 < n; i1++) {
    for (int j1 = 0; j1 < m; j1++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) dp[i1][j1][i][j] = 0;
      }
    }
  }
  int res = 1;
  for (int i1 = 0; i1 < n; i1++) {
    for (int j1 = 0; j1 < m; j1++) {
      for (int i2 = i1; i2 < n; i2++) {
        for (int j2 = j1; j2 < m; j2++) {
          if (v[i2][j2] == '1') continue;
          if (i1 == i2 and j1 == j2) {
            dp[i1][j1][i2][j2] = 1;
            res = max(res, 2 * (i2 - i1 + 1 + j2 - j1 + 1));
            continue;
          }
          if (j2 == j1 and i2 > i1 and dp[i1][j1][i2 - 1][j2] == 1) {
            dp[i1][j1][i2][j2] = 1;
            res = max(res, 2 * (i2 - i1 + 1 + j2 - j1 + 1));
            continue;
          }
          if (i2 == i1 and j2 > j1 and dp[i1][j1][i2][j2 - 1] == 1) {
            dp[i1][j1][i2][j2] = 1;
            res = max(res, 2 * (i2 - i1 + 1 + j2 - j1 + 1));
            continue;
          }
          if (dp[i1][j1][i2 - 1][j2] == 1 and dp[i1][j1][i2][j2 - 1] == 1) {
            dp[i1][j1][i2][j2] = 1;
            res = max(res, 2 * (i2 - i1 + 1 + j2 - j1 + 1));
            continue;
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
