#include <bits/stdc++.h>
using namespace std;
const int N = 26;
bool f[N][N][N][N];
char a[N][N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < m; j++) {
      a[i][j] = str[j];
    }
  }
  int ans = 0;
  for (int r1 = 0; r1 < n; r1++) {
    for (int c1 = 0; c1 < m; c1++) {
      for (int r2 = r1; r2 < n; r2++) {
        for (int c2 = c1; c2 < m; c2++) {
          f[r1][c1][r2][c2] = false;
        }
      }
      for (int r2 = r1; r2 < n; r2++) {
        for (int c2 = c1; c2 < m; c2++) {
          if (r2 == r1 && c2 == c1) {
            f[r1][c1][r2][c2] = (a[r1][c1] == '0');
          } else if (r2 == r1) {
            f[r1][c1][r2][c2] = (f[r1][c1][r2][c2 - 1] & (a[r2][c2] == '0'));
          } else if (c2 == c1) {
            f[r1][c1][r2][c2] = (f[r1][c1][r2 - 1][c2] & (a[r2][c2] == '0'));
          } else {
            f[r1][c1][r2][c2] = (f[r1][c1][r2 - 1][c2] & f[r1][c1][r2][c2 - 1] &
                                 (a[r2][c2] == '0'));
          }
          if (f[r1][c1][r2][c2])
            ans = max(ans, 2 * (abs(r1 - 1 - r2) + abs(c1 - 1 - c2)));
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
