#include <bits/stdc++.h>
using namespace std;
int sum[30][30];
int maze[30][30];
int main() {
  int m, n;
  int mx = 0;
  cin >> n >> m;
  char t;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> t;
      maze[i][j] = t - '0';
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      sum[i][j] = sum[i][j - 1] + maze[i][j];
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      sum[i][j] += sum[i - 1][j];
    }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      for (int a = i; a <= n; ++a)
        for (int b = j; b <= m; ++b) {
          if (sum[a][b] - sum[i - 1][b] - sum[a][j - 1] + sum[i - 1][j - 1] ==
                  0 &&
              mx < a - i + b - j + 2)
            mx = a - i + b - j + 2;
        }
    }
  }
  cout << mx * 2 << endl;
  return 0;
}
