#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int *a = new int[n];
  for (int i = 0; i < n; i++) {
    char *s = new char[m + 10];
    scanf("%s", s);
    a[i] = 0;
    for (int j = 0; j < m; j++)
      if (s[j] == '1') a[i] += (1 << j);
  }
  int ans = 0;
  for (int h = 1; h <= n; h++)
    for (int w = 1; w <= m; w++)
      if (h + w > ans) {
        for (int i = 0; i < n - h + 1; i++) {
          int cur = 0;
          for (int j = 0; j < h; j++) cur |= a[i + j];
          bool ok = 0;
          for (int j = 0; j < m - w + 1; j++)
            if (((cur >> j) & ((1 << w) - 1)) == 0) {
              ok = true;
              break;
            }
          if (ok) ans = h + w;
        }
      }
  int *b = new int[m];
  for (int i = 0; i < m; i++) {
    b[i] = 0;
    for (int j = 0; j < n; j++)
      if (a[j] & (1 << i)) b[i] += (1 << j);
  }
  swap(n, m);
  for (int h = 1; h <= n; h++)
    for (int w = 1; w <= m; w++)
      if (h + w > ans) {
        for (int i = 0; i < n - h + 1; i++) {
          int cur = 0;
          for (int j = 0; j < h; j++) cur |= b[i + j];
          bool ok = 0;
          for (int j = 0; j < m - w + 1; j++)
            if (((cur >> j) & ((1 << w) - 1)) == 0) {
              ok = true;
              break;
            }
          if (ok) ans = h + w;
        }
      }
  cout << ans * 2;
}
