#include <bits/stdc++.h>
using namespace std;
int N, M;
char T[30][30];
int SS[30][30];
int Max = -1;
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%s", T[i]);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      SS[i][j] = T[i - 1][j - 1] - '0' + SS[i][j - 1] + SS[i - 1][j] -
                 SS[i - 1][j - 1];
    }
  }
  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 (SS[k][l] - SS[k][j - 1] - SS[i - 1][l] + SS[i - 1][j - 1] == 0) {
            Max = max(Max, 2 * (k - i + 1 + l - j + 1));
          }
        }
      }
    }
  }
  printf("%d\n", Max);
}
