#include <bits/stdc++.h>
using namespace std;
bool adj[5220][5220];
int n;
vector<int> d;
bool work(int x) {
  int b = n / x, i, j, p, r, l;
  for (i = 1; i <= b; ++i) {
    for (j = 1; j <= b; ++j) {
      p = adj[i * x][j * x];
      for (l = 1 + (i - 1) * x; l <= i * x; ++l) {
        for (r = 1 + (j - 1) * x; r <= j * x; ++r) {
          if (adj[l][r] != p) return 0;
        }
      }
    }
  }
  return 1;
}
int bbin() {
  int ini = 0, fim = d.size() - 1, ans = 1, mid;
  int k = 0;
  while (ini <= fim && k < 25) {
    ++k;
    mid = (ini + fim) >> 1;
    if (work(d[mid])) {
      ini = mid;
      ans = d[mid];
    } else {
      fim = mid - 1;
    }
  }
  if (work(d[ini])) ans = max(ans, d[ini]);
  fim = max(fim, 0);
  if (work(d[fim])) ans = max(ans, d[fim]);
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  int x, i, j, k, w;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= (n >> 2); ++j) {
      scanf("%1x", &x);
      for (k = j << 2, w = 1; w <= 4; --k, ++w) {
        adj[i][k] = x & 1;
        x >>= 1;
      }
    }
  }
  for (i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      d.push_back(i);
      if (i * i != n) d.push_back(n / i);
    }
  }
  sort(d.begin(), d.end());
  printf("%d\n", bbin());
}
