#include <bits/stdc++.h>
using namespace std;
string a[30];
long long dp[30][30], n, m, ans;
int main() {
  scanf("%lld", &n), scanf("%lld", &m);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      memset(dp, -1, sizeof dp);
      dp[i][j] = 1;
      for (long long k = i; k < n; k++)
        for (long long l = j; l < m; l++) {
          if (k != i) dp[k][l] &= dp[k - 1][l];
          if (l != j) dp[k][l] &= dp[k][l - 1];
          dp[k][l] &= (a[k][l] == '0');
          if (dp[k][l]) ans = max(ans, k + l - i - j + 2);
        }
    }
  return 0 * printf("%lld ", 2 * ans);
}
