#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline string gets() {
  char ch[600];
  scanf("%s", ch);
  return ch;
}
template <class P, class Q>
inline P smin(P &a, Q b) {
  if (b < a) a = b;
  return a;
}
template <class P, class Q>
inline P smax(P &a, Q b) {
  if (a < b) a = b;
  return a;
}
const int MAX_LG = 17;
const long long maxn = 300 + 10;
const long long base = 29;
const long long mod = 1e9 + 9;
const long long INF = 1e9;
const long long maxq = 2e5 + 10;
const long long SQ = sqrt(maxn);
long long a[maxn][maxn];
long long sum[maxn][maxn];
long long res;
int32_t main() {
  long long n = in(), m = in();
  for (long long i = 0; i < n; i++) {
    string s = gets();
    for (long long j = 0; j < m; j++) {
      a[i][j] = (s[j] == '0');
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      sum[i][j] = a[i][j] + (j ? sum[i][j - 1] : 0) + (i ? sum[i - 1][j] : 0) -
                  (i && j ? sum[i - 1][j - 1] : 0);
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      for (long long i2 = i; i2 < n; i2++) {
        for (long long j2 = j; j2 < m; j2++) {
          long long cnt = sum[i2][j2] - (i ? sum[i - 1][j2] : 0) -
                          (j ? sum[i2][j - 1] : 0) +
                          (i && j ? sum[i - 1][j - 1] : 0);
          if (cnt == (i2 - i + 1) * (j2 - j + 1)) {
            long long val = 2 * (i2 - i + 1) + 2 * (j2 - j + 1);
            res = max(res, val);
          }
        }
      }
    }
  }
  cout << res << "\n";
}
