#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::istream;
using std::map;
using std::ostream;
using std::set;
using std::string;
using std::vector;
ostream &operator<<(ostream &os, const unsigned char v) {
  os << (int)v;
  return os;
}
istream &operator>>(istream &is, unsigned char &v) {
  int tmp;
  is >> tmp;
  v = (unsigned char)tmp;
  return is;
}
inline unsigned char min(unsigned char a, unsigned char b) {
  return (a < b) ? a : b;
}
inline unsigned char max(unsigned char a, unsigned char b) {
  return (a > b) ? a : b;
}
int pmod(int a, int b) {
  if (b < 0) {
    return pmod(-a, -b);
  }
  int ret = a % b;
  if (ret < 0) ret += b;
  return ret;
}
int n, m;
class Point {
 public:
  unsigned char i, j;
  Point() : i(-1), j(-1) {}
  Point(unsigned char hi, unsigned char hj) : i(hi), j(hj) {}
  void set(unsigned char hi, unsigned char hj) {
    i = hi;
    j = hj;
  }
};
bool dp[25][25][25][25];
bool table[25][25];
int main(int argc, const char *argv[]) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      table[i][j] = bool(s[j] - '0');
    }
  }
  int maxp = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!table[i][j]) {
        dp[(i)][(j)][(i)][(j)] = true;
        maxp = std::max(((i) - (i) + (j) - (j) + 2) << 1, maxp);
        for (int xi = 0; xi < i; xi++) {
          for (int xj = 0; xj < j; xj++) {
            if (dp[i - 1][j][xi][xj] && dp[i][j - 1][xi][xj]) {
              dp[(i)][(j)][(xi)][(xj)] = true;
              maxp = std::max(((i) - (xi) + (j) - (xj) + 2) << 1, maxp);
            }
          }
        }
        for (int xi = 0; xi < i; xi++) {
          if (dp[i - 1][j][xi][j]) {
            dp[(i)][(j)][(xi)][(j)] = true;
            maxp = std::max(((i) - (xi) + (j) - (j) + 2) << 1, maxp);
          }
        }
        for (int xj = 0; xj < j; xj++) {
          if (dp[i][j - 1][i][xj]) {
            dp[(i)][(j)][(i)][(xj)] = true;
            maxp = std::max(((i) - (i) + (j) - (xj) + 2) << 1, maxp);
          }
        }
      }
    }
  }
  cout << maxp << endl;
  return 0;
}
