#include <bits/stdc++.h>
using namespace std;
int visit[30][30][30][30];
char grid[30][30];
int n, m;
bool f(int xi, int yi, int xj, int yj) {
  if (xi == xj && yi == yj) {
    if (grid[xi][yi] == '1') {
      return false;
    } else {
      visit[xi][yi][xj][yj] = 1;
      return true;
    }
  }
  if (xi > xj || yi > yj) {
    return true;
  }
  if (visit[xi][yi][xj][yj] >= 0) {
    return visit[xi][yi][xj][yj];
  }
  if ((f(xi + 1, yi, xj, yj) & f(xi, yi + 1, xj, yj) & f(xi, yi, xj - 1, yj) &
       f(xi, yi, xj, yj - 1))) {
    visit[xi][yi][xj][yj] = 1;
  } else {
    visit[xi][yi][xj][yj] = 0;
  }
  return visit[xi][yi][xj][yj];
}
int main() {
  memset(visit, -1, sizeof(visit));
  memset(grid, '0', sizeof(grid));
  cin >> n >> m;
  int existe = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> grid[j][i];
      if (grid[j][i] == '0') {
        existe = 1;
      }
    }
  }
  int res = 0;
  (f(1, 1, m, n));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = i; k <= n; k++) {
        for (int l = j; l <= m; l++) {
          if (visit[j][i][l][k] == 1) {
            res = max(res, (k - i + 1) * 2 + (l - j + 1) * 2);
          }
        }
      }
    }
  }
  cout << res;
  return 0;
}
