#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5210;
char g[N][N];
bool st[N][N][2];
int n;
bool check(int k) {
  memset(st, 0, sizeof st);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      st[(i + k - 1) / k][(j + k - 1) / k][g[i][j] - '0'] = 1;
    }
  }
  bool ok = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (st[(i + k - 1) / k][(j + k - 1) / k][0] +
              st[(i + k - 1) / k][(j + k - 1) / k][1] ==
          2)
        ok = 1;
    }
  }
  return ok;
}
int main() {
  scanf("%d", &n);
  vector<int> dv;
  for (int j = 1; j * j <= n; j++) {
    if (n % j == 0) {
      dv.emplace_back(j);
      if (j != n / j) dv.emplace_back(n / j);
    }
  }
  sort(dv.begin(), dv.end());
  string val[200];
  val['0'] = "0000";
  val['1'] = "0001";
  val['2'] = "0010";
  val['3'] = "0011";
  val['4'] = "0100";
  val['5'] = "0101";
  val['6'] = "0110";
  val['7'] = "0111";
  val['8'] = "1000";
  val['9'] = "1001";
  val['A'] = "1010";
  val['B'] = "1011";
  val['C'] = "1100";
  val['D'] = "1101";
  val['E'] = "1110";
  val['F'] = "1111";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / 4; j++) {
      char c;
      scanf(" %c", &c);
      for (int k = 1; k <= 4; k++) g[i][((j - 1) * 4) + k] = val[c][k - 1];
    }
  }
  int lo = 0, hi = dv.size();
  while (lo < hi) {
    int mi = (lo + hi) / 2;
    if (check(dv[mi]))
      hi = mi;
    else
      lo = mi + 1;
  }
  printf("%d\n", dv[lo - 1]);
  return 0;
}
