#include <bits/stdc++.h>
using namespace std;
const int Nn = 1005;
int N, M, Mar[Nn][Nn], All = 0, Gcd, Nx[4] = {1, 0, -1, 0},
                       Ny[4] = {0, 1, 0, -1};
bool Exit() {
  for (int i = 1; i < N; i++)
    for (int j = 1; j < M; j++)
      if (Mar[i][j] && Mar[i + 1][j] && Mar[i + 1][j + 1] && Mar[i][j + 1]) {
        return 1;
      }
  return 0;
}
bool Vis[Nn][Nn], Flag[Nn];
int Calc(int x, int y) {
  if (x < 1 || y < 1 || x > N || y > M) return 0;
  ;
  if (!Mar[x][y] || Vis[x][y]) return 0;
  Vis[x][y] = 1;
  return Calc(x - 1, y) + Calc(x, y - 1) + Calc(x + 1, y) + Calc(x, y + 1) + 1;
}
bool NotOne() {
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (Mar[i][j]) {
        return Calc(i, j) != All;
      }
}
int GetGcd(int x, int y) { return y == 0 ? x : GetGcd(y, x % y); }
bool Check() {
  int cont = 0;
  memset(Vis, 0, sizeof(Vis));
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (Mar[i][j]) {
        int cnt = Mar[i][j - 1] + Mar[i - 1][j] + Mar[i][j + 1] + Mar[i + 1][j];
        cont += cnt & 1;
        if (cont >= 3) return 0;
        if (cnt == 2 && ((Mar[i][j - 1] && Mar[i][j + 1]) ||
                         (Mar[i - 1][j] && Mar[i + 1][j])))
          continue;
        Vis[i][j] = 1;
      }
  Gcd = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (Vis[i][j]) {
        int t;
        for (int k = 0; k < 3; k++) {
          for (t = 1; !Vis[i + Nx[k] * t][j + Ny[k] * t] &&
                      Mar[i + Nx[k] * t][j + Ny[k] * t];
               t++)
            ;
          if (t <= 1) continue;
          Flag[t] = 1;
          Gcd = t;
        }
      }
  for (int i = max(N, M); i > 1; i--)
    if (Flag[i]) Gcd = GetGcd(i, Gcd);
  return Gcd > 1;
}
void Print(int x) {
  for (int i = 2; i < x; i++)
    if (x % i == 0) printf("%d ", i);
  printf("%d\n", x);
}
int main() {
  memset(Mar, 0, sizeof(Mar));
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) scanf("%d", &Mar[i][j]), All += Mar[i][j];
  if (Exit() || NotOne()) {
    printf("-1\n");
    return 0;
  }
  if (Check())
    Print(Gcd);
  else
    printf("-1\n");
  return 0;
}

### Prompt

In CPP, your task is to solve the following problem:

Dima is a good person. In fact, he's great. But all good things come to an end...

Seryozha is going to kick Dima just few times.. For this reason he divides the room into unit squares. Now the room is a rectangle n × m consisting of unit squares.

For the beginning, Seryozha put Dima in a center of some square. Then he started to kick Dima (it is known, that he kicks Dima at least once). Each time when Dima is kicked he flyes up and moves into one of four directions (up, left, right, down). On each move Dima passes k (k > 1) unit of the length in the corresponding direction. Seryozha is really kind, so he kicks Dima in such way that Dima never meets the walls (in other words, Dima never leave the room's space). Seryozha is also dynamic character so Dima never flies above the same segment, connecting a pair of adjacent squares, twice.

Seryozha kicks Dima for a long time, but Dima is not vindictive — Dima writes. Dima marked all squares in which he was staying or above which he was flying. Thanks to kicks, Dima does not remember the k value, so he asks you to find all possible values which matches to the Dima's records.

Input

The first line contains n and m (1 ≤ n, m ≤ 103) — size of the room.

Next n lines goes, each contains m numbers aij — Dima's notes: aij = 1, if Dima was staying in the square (i, j) or was flying above it. Otherwise aij = 0.

At least one aij equals 1.

Output

In a single line in accending order print all k (k > 1), which matches the Dima's notes. If there are no such k and Dima invented this story with kicks, print -1.

Examples

Input

5 5
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1


Output

2 4


Input

7 7
0 0 1 1 1 0 0
0 0 1 0 1 0 0
1 1 1 1 1 1 1
1 0 1 0 1 0 1
1 1 1 1 1 1 1
0 0 1 0 1 0 0
0 0 1 1 1 0 0


Output

2


Input

3 3
1 1 1
1 1 1
1 1 1


Output

-1


Input

4 4
1 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0


Output

3


Input

5 5
0 0 1 0 0
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
0 0 1 0 0


Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Nn = 1005;
int N, M, Mar[Nn][Nn], All = 0, Gcd, Nx[4] = {1, 0, -1, 0},
                       Ny[4] = {0, 1, 0, -1};
bool Exit() {
  for (int i = 1; i < N; i++)
    for (int j = 1; j < M; j++)
      if (Mar[i][j] && Mar[i + 1][j] && Mar[i + 1][j + 1] && Mar[i][j + 1]) {
        return 1;
      }
  return 0;
}
bool Vis[Nn][Nn], Flag[Nn];
int Calc(int x, int y) {
  if (x < 1 || y < 1 || x > N || y > M) return 0;
  ;
  if (!Mar[x][y] || Vis[x][y]) return 0;
  Vis[x][y] = 1;
  return Calc(x - 1, y) + Calc(x, y - 1) + Calc(x + 1, y) + Calc(x, y + 1) + 1;
}
bool NotOne() {
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (Mar[i][j]) {
        return Calc(i, j) != All;
      }
}
int GetGcd(int x, int y) { return y == 0 ? x : GetGcd(y, x % y); }
bool Check() {
  int cont = 0;
  memset(Vis, 0, sizeof(Vis));
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (Mar[i][j]) {
        int cnt = Mar[i][j - 1] + Mar[i - 1][j] + Mar[i][j + 1] + Mar[i + 1][j];
        cont += cnt & 1;
        if (cont >= 3) return 0;
        if (cnt == 2 && ((Mar[i][j - 1] && Mar[i][j + 1]) ||
                         (Mar[i - 1][j] && Mar[i + 1][j])))
          continue;
        Vis[i][j] = 1;
      }
  Gcd = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (Vis[i][j]) {
        int t;
        for (int k = 0; k < 3; k++) {
          for (t = 1; !Vis[i + Nx[k] * t][j + Ny[k] * t] &&
                      Mar[i + Nx[k] * t][j + Ny[k] * t];
               t++)
            ;
          if (t <= 1) continue;
          Flag[t] = 1;
          Gcd = t;
        }
      }
  for (int i = max(N, M); i > 1; i--)
    if (Flag[i]) Gcd = GetGcd(i, Gcd);
  return Gcd > 1;
}
void Print(int x) {
  for (int i = 2; i < x; i++)
    if (x % i == 0) printf("%d ", i);
  printf("%d\n", x);
}
int main() {
  memset(Mar, 0, sizeof(Mar));
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) scanf("%d", &Mar[i][j]), All += Mar[i][j];
  if (Exit() || NotOne()) {
    printf("-1\n");
    return 0;
  }
  if (Check())
    Print(Gcd);
  else
    printf("-1\n");
  return 0;
}

```