#include <bits/stdc++.h>
using namespace std;
struct myhash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long modpow(long long base, long long exp, long long modulus) {
  base %= modulus;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
long long modinv(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<vector<bool>> a(n, vector<bool>(n, 0));
  for (long long(i) = (0); i < (n); ++(i)) {
    string s;
    cin >> s;
    for (long long(j) = (0); j < (n / 4); ++(j)) {
      int val = 0;
      if (s[j] >= '0' && s[j] <= '9') {
        val = (s[j] - '0');
      } else {
        val = (10 + (s[j] - 'A'));
      }
      for (long long(k) = (0); k < (4); ++(k)) {
        a[i][j * 4 + k] = ((val & (1LL << (3 - k))) != 0);
      }
    }
  }
  vector<long long> pfactors(0);
  long long nc = n;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      pfactors.push_back(i);
      while ((n != 1) && (n % i == 0)) n /= i;
    }
  }
  n = nc;
  long long x = 1;
  for (long long(h) = (0); h < (pfactors.size()); ++(h)) {
    long long sz = pfactors[h];
  lab:
    bool works = true;
    for (long long(I) = (0); I < (n / sz); ++(I)) {
      for (long long(J) = (0); J < (n / sz); ++(J)) {
        bool what = a[I * sz][J * sz];
        for (long long(i) = (0); i < (sz); ++(i)) {
          for (long long(j) = (0); j < (sz); ++(j)) {
            if (a[I * sz + i][J * sz + j] ^ what) {
              works = false;
              break;
            }
          }
          if (!works) break;
        }
        if (!works) break;
      }
      if (!works) break;
    }
    if (works) {
      x = sz;
      sz *= pfactors[h];
      if (n % sz == 0) {
        goto lab;
      }
    }
  }
  cout << x << "\n";
  return 0;
}
