#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[30][30];
char Eula[30][30];
void YaeKasumi() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> Eula[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
      if (Eula[i][j] == '1') a[i][j]++;
    }
  }
  long long res = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      for (long long k = i; k <= n; k++) {
        for (long long l = j; l <= m; l++) {
          if (a[i - 1][j - 1] + a[k][l] - a[i - 1][l] - a[k][j - 1] == 0) {
            res = max(res, 2 * ((k - i + 1) + (l - j + 1)));
          }
        }
      }
    }
  }
  cout << res;
}
signed main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  YaeKasumi();
  return 0;
}
