#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn = 5200;
int cnv(char c) {
  if (c <= '9')
    return c - '0';
  else
    return c - 'A' + 10;
}
void solve() {
  int n;
  scanf("%d", &n);
  char buffer[4 * mxn];
  bitset<mxn> a[mxn];
  for (int i = 0; i < n; i++) {
    scanf("%s", buffer);
    string s(buffer);
    for (int j = 0; j < n; j++) {
      int temp = cnv(s[j / 4]);
      int k = (3 - (j % 4));
      a[i][j] = temp >> k & 1;
    }
  }
  vector<int> ls;
  ls.push_back(1);
  for (int i = 2; i * i <= n; i++)
    if (!(n % i)) {
      ls.push_back(i);
      ls.push_back(n / i);
    }
  ls.push_back(n);
  auto check = [&](int x) {
    int ni = -1;
    for (int i = 0; i < n; i++) {
      if (!(i % x)) ni++;
      int nj = -1;
      for (int j = 0; j < n; j++) {
        if (!(j % x)) nj++;
        if (a[i][j] != a[ni][nj]) return false;
      }
    }
    return true;
  };
  check(4);
  sort(ls.begin(), ls.end());
  while (int((ls).size())) {
    int x = ls.back();
    ls.pop_back();
    if (check(x)) {
      cout << x << endl;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
