#include <bits/stdc++.h>
using namespace std;
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
int cum[30][30];
int main() {
  char ch;
  int n, m;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        cin >> ch;
        cum[i][j] =
            cum[i - 1][j] + cum[i][j - 1] - cum[i - 1][j - 1] + (int)(ch - '0');
      }
    }
    int mx = 0;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j)
        for (int k = i; k <= n; ++k)
          for (int l = j; l <= m; ++l) {
            int sum =
                cum[k][l] - cum[i - 1][l] - cum[k][j - 1] + cum[i - 1][j - 1];
            if (!sum) {
              mx = max(mx, 2 * (k - i + l - j + 2));
            }
          }
    cout << mx << endl;
  }
  return 0;
}
