#include <bits/stdc++.h>
bool office[25][25];
size_t m, n;
bool check(size_t x1, size_t y1, size_t x2, size_t y2) {
  for (size_t x = x1; x <= x2; ++x) {
    for (size_t y = y1; y <= y2; ++y) {
      if (office[x][y]) {
        return false;
      }
    }
  }
  return true;
}
bool check(size_t x, size_t y) {
  for (size_t i = 0; i < m - x; ++i) {
    for (size_t j = 0; j < n - y; ++j) {
      if (check(i, j, i + x, j + y)) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  std::cin >> m >> n;
  std::string row;
  size_t i = 0;
  while (std::cin >> row) {
    for (size_t j = 0; j < row.size(); ++j) {
      office[i][j] = row[j] == '1';
    }
    ++i;
  }
  size_t best = 4;
  for (size_t x = 0; x < m; ++x) {
    for (size_t y = 0; y < n; ++y) {
      size_t p = (x + y + 2) * 2;
      if (p > best && check(x, y)) {
        best = p;
      }
    }
  }
  std::cout << best;
}
