#include <bits/stdc++.h>
using namespace std;
int N, M;
char grid[26][26];
int getArea(int a, int b, int c, int d) {
  int rowSt = min(a, c);
  int rowEn = max(a, c);
  int colSt = min(b, d);
  int colEn = max(b, d);
  for (int i = rowSt; i <= rowEn; i++) {
    for (int j = colSt; j <= colEn; j++) {
      if (grid[i][j] == '1') return -1;
    }
  }
  return ((rowEn - rowSt + 1) + (colEn - colSt + 1)) * 2;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> grid[i][j];
    }
  }
  int sol = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      for (int k = 0; k < N; k++) {
        for (int l = 0; l < M; l++) {
          sol = max(sol, getArea(i, j, k, l));
        }
      }
    }
  }
  cout << sol << endl;
  return 0;
}
