#include <bits/stdc++.h>
using namespace std;
struct Pos {
  Pos(int x_, int y_) : x(x_), y(y_) {}
  int x;
  int y;
  bool operator<(const Pos& b) const {
    return (x <= b.x && y < b.y) || (x < b.x && y <= b.y);
  }
  bool operator==(const Pos& b) const { return x == b.x && y == b.y; }
};
struct Rect {
  Rect(int x1, int y1, int x2, int y2) : ul(x1, y1), dr(x2, y2) {}
  Pos ul;
  Pos dr;
  bool operator<(const Rect& b) const {
    if (ul.x < b.ul.x)
      return true;
    else if (ul.x > b.ul.x)
      return false;
    else if (ul.y < b.ul.y)
      return true;
    else if (ul.y > b.ul.y)
      return false;
    else if (dr.x < b.dr.x)
      return true;
    else if (dr.x > b.dr.x)
      return false;
    else
      return (dr.y < b.dr.y);
  }
  bool contains(const Pos& p) const {
    return (ul < p || ul == p) && (p < dr || p == dr);
  }
  vector<Rect> split(const Pos& p) const {
    vector<Rect> result;
    int x1 = ul.x;
    int y1 = ul.y;
    int x2 = dr.x;
    int y2 = dr.y;
    int x = p.x;
    int y = p.y;
    if (y > y1) result.push_back(Rect(x1, y1, x2, y - 1));
    if (x > x1) result.push_back(Rect(x1, y1, x - 1, y2));
    if (y < y2) result.push_back(Rect(x1, y + 1, x2, y2));
    if (x < x2) result.push_back(Rect(x + 1, y1, x2, y2));
    return result;
  }
  int perim() const { return 2 * ((dr.x - ul.x + 1) + (dr.y - ul.y + 1)); }
};
int main() {
  int m, n;
  cin >> m >> n;
  vector<Pos> occupied;
  set<Rect> rects;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      char x;
      cin >> x;
      if (x == '1') occupied.push_back(Pos(j, i));
    }
  }
  rects.insert(Rect(0, 0, n - 1, m - 1));
  for (vector<Pos>::const_iterator it = occupied.begin(); it != occupied.end();
       ++it) {
    for (set<Rect>::iterator rit = rects.begin(); rit != rects.end();) {
      if (rit->contains(*it)) {
        Rect r = (*rit);
        rects.erase(rit++);
        vector<Rect> splits = r.split(*it);
        rects.insert(splits.begin(), splits.end());
      } else {
        ++rit;
      }
    }
  }
  int result = 0;
  for (set<Rect>::const_iterator rit = rects.begin(); rit != rects.end();
       ++rit) {
    result = max(result, rit->perim());
  }
  cout << result << endl;
  return 0;
}
