#include <bits/stdc++.h>
using namespace std;
int acc[25 + 5][25 + 5];
char str[25 + 5][25 + 5];
int main() {
  int N, M, ans = 0;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) scanf("%s", str[i]);
  for (int i = 1; i < N + 1; i++)
    for (int j = 1; j < M + 1; j++)
      acc[i][j] = acc[i - 1][j] + acc[i][j - 1] - acc[i - 1][j - 1] +
                  (str[i - 1][j - 1] == '0' ? 1 : 0);
  for (int r1 = 1; r1 < N + 1; r1++)
    for (int c1 = 1; c1 < M + 1; c1++)
      for (int r2 = r1; r2 < N + 1; r2++)
        for (int c2 = c1; c2 < M + 1; c2++)
          if (acc[r2][c2] - acc[r1 - 1][c2] - acc[r2][c1 - 1] +
                  acc[r1 - 1][c1 - 1] ==
              (r2 - r1 + 1) * (c2 - c1 + 1))
            ans = max(ans, 2 * ((r2 - r1 + 1) + (c2 - c1 + 1)));
  printf("%d\n", ans);
  return 0;
}
