#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
void PA(const T (&a)[N], int n = -1) {
  if (!n) n = N;
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << '\n';
}
template <typename T, size_t N, size_t M>
void PA(const T (&a)[N][M], int n, int m) {
  for (int i = 0; i < n; i++) PA(a[i], m);
  cout << '\n';
}
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
struct cmp {
  bool operator()(const pair<int, int>& a, const pair<int, int>& b) const {
    if (a.first != b.first)
      return a.first > b.first;
    else
      return a.second < b.second;
  }
};
template <typename T>
T power(T x, int y) {
  if (y == 0) return 1;
  if (x == 0) return 0;
  return x * power(x, y - 1);
}
int left_dp[27][27], top_dp[27][27];
bool arr[27][27];
char ch;
int n, m, ans;
int get_cords_sum(int x, int y) { return left_dp[x][y]; }
int get_sum(int x1, int y1, int x2, int y2) {
  int t2 = get_cords_sum(x2, y2);
  return t2 - (y1 ? get_cords_sum(x2, y1 - 1) : 0) -
         (x1 ? get_cords_sum(x1 - 1, y2) : 0) +
         ((x1 && y1) ? get_cords_sum(x1 - 1, y1 - 1) : 0);
}
int get_perimeter(int x1, int y1, int x2, int y2) {
  return 2 * ((x2 - x1 + 1) + (y2 - y1 + 1));
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> ch;
      arr[i][j] = ch == '1';
      left_dp[i][j] = arr[i][j];
      top_dp[i][j] = arr[i][j];
    }
  for (int i = 0; i < n; i++)
    for (int j = 1; j < m; j++) left_dp[i][j] += left_dp[i][j - 1];
  for (int j = 0; j < m; j++)
    for (int i = 1; i < n; i++) left_dp[i][j] += left_dp[i - 1][j];
  ans = 0;
  for (int x1 = 0; x1 < n; x1++)
    for (int x2 = x1; x2 < n; x2++)
      for (int y1 = 0; y1 < m; y1++)
        for (int y2 = y1; y2 < m; y2++)
          if (!get_sum(x1, y1, x2, y2))
            ans = max(ans, get_perimeter(x1, y1, x2, y2));
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
