Little Petya very much likes rectangular tables that consist of characters "0" and "1". Recently he has received one such table as a gift from his mother. The table contained n rows and m columns. The rows are numbered from top to bottom from 1 to n, the columns are numbered from the left to the right from 1 to m. Petya immediately decided to find the longest cool cycle whatever it takes.

A cycle is a sequence of pairwise distinct cells where each two consecutive cells have a common side; besides, the first cell has a common side with the last cell. A cycle is called cool if it fulfills all the following conditions simultaneously: 

  * The cycle entirely consists of the cells that contain "1". 
  * Each cell that belongs to the cycle, has a common side with exactly two other cells that belong to the cycle. 
  * Each cell of the table that contains "1" either belongs to the cycle or is positioned outside of it (see definition below). 



To define the notion of "outside" formally, let's draw a cycle on a plane. Let each cell of the cycle (i, j) (i is the row number, j is the column number) correspond to the point (i, j) on the coordinate plane. Let a straight line segment join each pair of points that correspond to the cells belonging to the cycle and sharing a side. Thus, we will get a closed polyline that has no self-intersections and self-touches. The polyline divides the plane into two connected parts: the part of an infinite area and the part of a finite area. It is considered that cell (r, c) lies outside of the cycle if it does not belong to the cycle and the corresponding point on the plane with coordinates (r, c) lies in the part with the infinite area.

Help Petya to find the length of the longest cool cycle in the table. The cycle length is defined as the number of cells that belong to the cycle.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the table, respectively. Each of the following n lines contains m characters. Each character can be either "0" or "1".

Output

Print a single number — the length of the longest cool cycle in the table. If such cycles do not exist, print 0.

Examples

Input

3 3
111
101
111


Output

8


Input

5 5
01010
10101
01010
10101
01010


Output

0


Input

7 7
1111111
1000101
1000101
1000101
1000111
1000001
1111111


Output

24


Input

5 5
11111
10001
10101
10001
11111


Output

0

Note

In the first example there's only one cycle and it is cool.

In the second sample there's no cycle at all.

In the third sample there are two cool cycles: their lengths are 12 and 24.

In the fourth sample there also is only one cycle but it isn't cool as there's a cell containing "1" inside this cycle.
#include <bits/stdc++.h>
using namespace std;
const double E = 1e-10;
const int inf = (int)1e9;
const int maxn = 1010;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int n, m;
char s[maxn][maxn];
int mark[maxn][maxn];
int b[maxn][maxn];
int mc = 0;
pair<int, int> q[maxn * maxn];
int st, en;
int res = 0;
bool good;
int bx, by, cur, cur2;
inline bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
void bfs(int x, int y) {
  st = 0, en = 0;
  mark[x][y] = 1;
  q[en++] = make_pair(x, y);
  while (st < en) {
    pair<int, int> h = q[st++];
    for (int k = 0; k < 8; k++) {
      int x2 = h.first + dx8[k];
      int y2 = h.second + dy8[k];
      if (in(x2, y2)) {
        if (s[x2][y2] == '0' && mark[x2][y2] == 0) {
          mark[x2][y2] = 1;
          q[en++] = make_pair(x2, y2);
        }
      } else {
        good = false;
        return;
      }
    }
    for (int k = 0; k < 8; k++) {
      int x2 = h.first + dx8[k];
      int y2 = h.second + dy8[k];
      if (in(x2, y2)) {
        if (s[x2][y2] == '1') {
          if (b[x2][y2] < mc) cur++;
          b[x2][y2] = mc;
          bx = x2, by = y2;
        }
      }
    }
  }
}
void bfs2(int x, int y) {
  st = 0, en = 0;
  mark[x][y] = mc;
  q[en++] = make_pair(x, y);
  while (st < en) {
    cur2++;
    pair<int, int> h = q[st++];
    int curc = 0;
    for (int k = 0; k < 4; k++) {
      int x2 = h.first + dx[k];
      int y2 = h.second + dy[k];
      if (!in(x2, y2)) continue;
      if (b[x2][y2] == mc) {
        curc++;
        if (mark[x2][y2] < mc) {
          mark[x2][y2] = mc;
          q[en++] = make_pair(x2, y2);
        }
      }
    }
    if (curc != 2) {
      good = false;
      return;
    }
  }
}
int main() {
  srand(time(NULL));
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s\n", s[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '0' && mark[i][j] == 0) {
        good = true, ++mc, cur = 0, cur2 = 0;
        bfs(i, j);
        if (!good || cur == 0) continue;
        bfs2(bx, by);
        if (good && cur == cur2) res = max(res, cur);
      }
    }
  for (int i = 0; i < n - 1; i++)
    for (int j = 0; j < m - 1; j++) {
      bool ans = true;
      for (int di = 0; di <= 1; di++)
        for (int dj = 0; dj <= 1; dj++) ans &= s[i + di][j + dj] == '1';
      if (ans) res = max(res, 4);
    }
  printf("%d\n", res);
  return 0;
}
