#include <bits/stdc++.h>
using namespace std;
int arr[50][50];
int main() {
  int n, m;
  char c;
  while (scanf("%d %d", &n, &m) != -1) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        scanf(" %c", &c);
        arr[i][j + 1] = c - '0' + arr[i][j];
      }
    }
    int res = 0;
    for (int i = 0; i < m; ++i) {
      for (int j = i + 1; j <= m; ++j) {
        int cnt = 0, start = 0, end = 0;
        while (end < n) {
          while (cnt && start < end) {
            cnt -= (arr[start][j] - arr[start][i]);
            ++start;
          }
          while (end <= n && !cnt) {
            if (end != start) {
              res = max(res, 2 * (j - i) + 2 * (end - start));
            }
            cnt += (arr[end][j] - arr[end][i]);
            end++;
          }
        }
      }
    }
    printf("%d\n", res);
  }
  fflush(stdout);
  return 0;
}
