#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
long long mod = 1e9 + 7;
int m, mx, my;
int c[30][30], ch[30][30];
void sol(int i, int j) {
  for (int u = 0; u < i; ++u) {
    for (int v = 0; v < j; ++v) {
      int sum = ch[i][j] - ch[i][v] - ch[u][j] + ch[u][v];
      if (!sum) {
        int x = i - u;
        int y = j - v;
        int ans;
        if (x == 1)
          ans = y + y + 2;
        else if (y == 1)
          ans = x + x + 2;
        else
          ans = x * 2 + y * 2;
        mx = max(mx, ans);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < m; ++j) {
      c[i][j + 1] = s[j] - '0';
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      ch[i][j] = ch[i - 1][j] + ch[i][j - 1] - ch[i - 1][j - 1] + c[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      sol(i, j);
    }
  }
  cout << mx;
  return 0;
}
