#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s[26];
  for (int i = 0; i < n; i++) cin >> s[i];
  int mx = -1, q;
  bool f;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      q = m;
      if (s[i][j] == '0')
        for (int k = i; k < n; k++) {
          f = 1;
          for (int l = j; l < q; l++)
            if (s[k][l] == '1') {
              if (l - j && 2 * ((k - i + 1) + (l - j)) > mx)
                mx = 2 * ((k - i + 1) + (l - j));
              q = l;
              f = 0;
              break;
            }
          if (q - j && f && 2 * ((k - i + 1) + (q - j)) > mx)
            mx = 2 * ((k - i + 1) + (q - j));
        }
    }
  cout << mx << endl;
  return 0;
}
