#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using tpi = pair<pii, int>;
using tpl = pair<pll, ll>;
const ll mod = 1e9 + 7;
template <typename T>
T pwTwo(T val) {
  return (T)1 << val;
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << '\n';
  err(++it, args...);
}
struct CP {
  CP() {}
  void solN(int id) {
    int n, m;
    cin >> n >> m;
    char room[30][30];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> room[i][j];
      }
    }
    auto MaxLen = [room, &n, &m](int i, int j, bool nw) {
      if (nw) {
        int tot = 0;
        for (__typeof(m) indj = (j) - ((j) > (m)); indj != (m) - ((j) > (m));
             indj += 1 - 2 * ((j) > (m))) {
          if (room[i][indj] == '1') return tot;
          tot++;
        }
        return tot;
      }
      int tot = 0;
      for (__typeof(n) indi = (i) - ((i) > (n)); indi != (n) - ((i) > (n));
           indi += 1 - 2 * ((i) > (n))) {
        if (room[indi][j] == '1') return tot;
        tot++;
      }
      return tot;
    };
    auto ok = [room](int i, int j, int len, int wid) {
      for (__typeof(wid + i) I = (i) - ((i) > (wid + i));
           I != (wid + i) - ((i) > (wid + i)); I += 1 - 2 * ((i) > (wid + i))) {
        for (__typeof(len + j) J = (j) - ((j) > (len + j));
             J != (len + j) - ((j) > (len + j));
             J += 1 - 2 * ((j) > (len + j))) {
          if (room[I][J] == '1') return false;
        }
      }
      return true;
    };
    int mx = 0;
    for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      for (__typeof(m) j = (0) - ((0) > (m)); j != (m) - ((0) > (m));
           j += 1 - 2 * ((0) > (m))) {
        if (room[i][j] == '1') continue;
        int mxC = MaxLen(i, j, 1);
        int mxR = MaxLen(i, j, 0);
        int tmp = mxC;
        while (tmp) {
          int len = tmp--, wid = mxR;
          while (wid) {
            if (ok(i, j, len, wid)) {
              mx = max(mx, 2 * (len + wid));
            }
            wid--;
          }
        }
        while (mxR) {
          int len = mxC, wid = mxR--;
          while (len) {
            if (ok(i, j, len, wid)) {
              mx = max(mx, 2 * (len + wid));
            }
            len--;
          }
        }
      }
    }
    cout << mx << '\n';
  }
};
void Local() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1, id = 1;
  CP think;
  --t;
  do {
    think.solN(id++);
  } while (t--);
  return 0;
}
