#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool a[26][26];
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < m; j++) a[i][j] = (s[j] - '0' == 0 ? false : true);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool temp[26] = {false};
    for (int j = i; j < n; j++) {
      for (int k = 0; k < m; k++) temp[k] |= a[j][k];
      int ml = 0, l = 0;
      for (int k = 0; k < m; k++) {
        if (temp[k])
          ml = max(ml, l), l = 0;
        else
          l++;
      }
      ml = max(ml, l);
      if (ml) ans = max(ans, (j - i + 1) * 2 + ml * 2);
    }
  }
  cout << ans;
  return 0;
}
