#include <bits/stdc++.h>
using namespace std;
char A[30][30], B[30][30];
int N, M, i, j, maxi, k, l, sq;
int go(int a, int b, int c, int d) {
  int u, v;
  for (u = a; u <= b; u++)
    for (v = c; v <= d; v++)
      if (A[u][v] == '1') return 0;
  return 2 * (b - a + d - c + 2);
}
void solve() {
  for (k = 1; k <= N; k++)
    for (l = 1; l <= M; l++)
      for (i = 1; i <= N; i++)
        for (j = 1; j <= M; j++)
          if (i + k - 1 <= N && j + l - 1 <= M) {
            sq = go(i, i + k - 1, j, j + l - 1);
            if (sq > maxi) maxi = sq;
          }
}
int main(int argc, char *argv[]) {
  cin >> N >> M;
  for (i = 1; i <= N; i++)
    for (j = 1; j <= M; j++) cin >> A[i][j];
  maxi = 0;
  solve();
  for (i = 1; i <= N; i++)
    for (j = 1; j <= M; j++) B[j][i] = A[i][j];
  swap(N, M);
  for (i = 1; i <= N; i++)
    for (j = 1; j <= M; j++) A[i][j] = B[i][j];
  solve();
  cout << maxi << endl;
  return 0;
}
