#include <bits/stdc++.h>
using namespace std;
const int N = 25 + 5;
bool d[N][N][N][N], arr[N][N];
int out = 0;
int n, m;
void init() {
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= n; k++)
        for (int l = 0; l <= m; l++) {
          if (i == k && j == l && arr[i][j] == true)
            d[i][j][k][l] = true, out = 2;
          else if (k < i || l < j)
            d[i][j][k][l] = true;
          else
            d[i][j][k][l] = false;
        }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= m; j++) arr[i][j] = (s[j - 1] == '0' ? true : false);
  }
  init();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = i; k <= n; k++)
        for (int l = j; l <= m; l++) {
          if (d[i][j][k - 1][l] == true && d[i][j][k][l - 1] == true &&
              arr[k][l] == true)
            d[i][j][k][l] = true;
          if (d[i][j][k][l] == true) out = max((k + l - i - j + 2), out);
        }
  cout << out * 2 << endl;
  return 0;
}
