#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double pi = acos(-1.0);
int a[50][50], dp[50][50];
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    string s;
    for (int i = 0; i < n; i++) {
      cin >> s;
      for (int j = 0; j < (int)s.length(); j++) {
        if (s[j] == '0')
          a[i][j] = 0;
        else
          a[i][j] = 1;
      }
    }
    int perimeter = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = i; k < n; k++) {
          for (int l = j; l < m; l++) {
            int flag = 0;
            for (int x = i; x < k + 1; x++) {
              for (int y = j; y < l + 1; y++) {
                if (a[x][y] == 1) {
                  flag = 1;
                  break;
                }
              }
              if (flag) break;
            }
            if (!flag) {
              perimeter = ((perimeter) > (2 * (l - j + 1 + k - i + 1))
                               ? (perimeter)
                               : (2 * (l - j + 1 + k - i + 1)));
            }
          }
        }
      }
    }
    cout << perimeter << endl;
  }
  return 0;
}
