#include <bits/stdc++.h>
char s[30][30];
int main() {
  int a, b, d, i, j, k, l, ss = 0;
  scanf("%d%d", &a, &b);
  for (i = 0; i < a; i++) scanf("%s", s[i]);
  for (i = 0; i < a; i++) {
    for (j = 0; j < b; j++) {
      d = 99999999;
      if (s[i][j] == '0')
        for (k = 0; k <= i; k++) {
          if (s[i - k][j] == '1') break;
          for (l = 1; l <= j; l++) {
            if (s[i - k][j - l] == '1') break;
          }
          if (d > l) d = l;
          if (ss < d * 2 + k * 2 + 2) ss = d * 2 + k * 2 + 2;
        }
    }
  }
  printf("%d\n", ss);
}
