#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T a) {
  return a * a;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  char s[30][30];
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  int best = 0;
  int dp[30][30];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      memset(dp, 0, sizeof(dp));
      for (int ii = i; ii < n; ii++)
        for (int jj = j; jj < m; jj++) {
          int a1 = ii > i && dp[ii - 1][jj];
          int a2 = jj > j && dp[ii][jj - 1];
          dp[ii][jj] = s[ii][jj] == '1' || a1 || a2;
          if (!dp[ii][jj]) best = max(best, ii + jj - i - j + 2);
        }
    }
  printf("%d", best * 2);
  return 0;
}
