#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "";
  for (auto it = a.begin(); it != a.end(); it++) {
    if (it != a.begin()) out << " ";
    out << *it;
  }
  out << "";
  return out;
}
template <class A, class B>
istream& operator>>(istream& in, pair<A, B>& a) {
  in >> a.first >> a.second;
  return in;
}
template <class A>
istream& operator>>(istream& in, vector<A>& a) {
  for (A& i : a) in >> i;
  return in;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long r, c;
  cin >> r >> c;
  vector<vector<long long> > v(r, vector<long long>(c));
  bool dp[25][25][25][25] = {false};
  for (long long i = 0; i < r; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < c; j++) {
      v[i][j] = (s[j] - '0');
      if (v[i][j] == 0) dp[i][j][i][j] = true;
    }
  }
  long long ans = -1;
  for (long long i = 0; i < r; i++) {
    for (long long j = 0; j < c; j++) {
      if (dp[i][j][i][j]) {
        ans = max(ans, 4LL);
      }
    }
  }
  for (long long i = 0; i < r; i++) {
    for (long long j = 0; j < c; j++) {
      for (long long p = i + 1; p < r; p++) {
        dp[i][j][p][j] = (dp[i][j][p - 1][j] && (v[p][j] == 0));
        if (dp[i][j][p][j]) {
          ans = max(ans, 2 * (p - i) + 4LL);
        }
      }
    }
  }
  for (long long i = 0; i < r; i++) {
    for (long long j = 0; j < c; j++) {
      for (long long q = j + 1; q < c; q++) {
        dp[i][j][i][q] = (dp[i][j][i][q - 1] && (v[i][q] == 0));
        if (dp[i][j][i][q]) {
          ans = max(ans, 2 * (q - j) + 4LL);
        }
      }
    }
  }
  for (long long i = 0; i < r; i++) {
    for (long long j = 0; j < c; j++) {
      for (long long p = i + 1; p < r; p++) {
        for (long long q = j + 1; q < c; q++) {
          dp[i][j][p][q] =
              (dp[i][j][p - 1][q] && dp[i][j][p][q - 1] && (v[p][q] == 0));
          if (dp[i][j][p][q] == true) {
            ans = max(ans, 2 * (p - i + q - j + 2));
          }
        }
      }
    }
  }
  cout << ans;
}
