#include <bits/stdc++.h>
using namespace std;
int matrix[30][30];
int n, m;
int find(int x1, int y1, int x2, int y2) {
  for (int i = x1; i <= x2; i++) {
    if (matrix[i][y1] > 0 && matrix[i][y2] > 0 &&
        matrix[i][y2] - matrix[i][y1] == y2 - y1)
      continue;
    return 0;
  }
  return 2 * ((x2 - x1 + 1) + (y2 - y1 + 1));
}
int solve() {
  int maximum = -100000000;
  for (int x1 = 0; x1 < n; x1++)
    for (int y1 = 0; y1 < m; y1++)
      for (int x2 = x1; x2 < n; x2++)
        for (int y2 = y1; y2 < m; y2++)
          maximum = max(maximum, find(x1, y1, x2, y2));
  return maximum;
}
int main() {
  string s;
  scanf("%d %d", &n, &m);
  getline(cin, s);
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    for (int j = 0; j < m; j++) {
      if (s.at(j) == '0') {
        if (j > 0)
          matrix[i][j] = matrix[i][j - 1] + 1;
        else
          matrix[i][j] = 1;
      } else
        matrix[i][j] = 0;
    }
  }
  printf("%d\n", solve());
  return 0;
}
