#include <bits/stdc++.h>
using namespace std;
int a[150][150];
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    if (n % 2 == 1) {
      printf("%d\n", n);
      continue;
    } else {
      for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
          int ok = 0;
          int tmp = i;
          for (int j = 0;; j++) {
            if (tmp == n) {
              ok = 1;
              break;
            }
            if (tmp > n) {
              ok = 0;
              break;
            }
            tmp *= 2;
          }
          if (ok == 0) continue;
          ok = 1;
          int x = 0, y = 0, flag = 1;
          for (int j = 0; j < n; j++) {
            for (int k = 0; k < m; k++) {
              if (a[j][k] == a[x][y]) {
                if (flag == 1) {
                  y++;
                  if (y >= m) y = 0, x++;
                  if (x == i) {
                    flag = 0;
                    x = i - 1;
                    y = 0;
                  }
                } else {
                  y++;
                  if (y >= m) y = 0, x--;
                  if (x == -1) {
                    flag = 1;
                    x = 0;
                    y = 0;
                  }
                }
              } else
                ok = 0;
            }
          }
          if (ok == 1) {
            printf("%d\n", i);
            break;
          }
        }
      }
    }
  }
}
