#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1e9 + 7;
const int64_t primm = 998244353;
long long n, t, tiv[5204], q, ans;
vector<long long> a, b;
char c[5204];
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  cin >> n;
  for (long long i = 0; i < (long long)n; i++) {
    cin >> c;
    for (long long j = (long long)n / 4 - 1; j >= 0; j--) {
      if (c[j] - '0' > 9)
        t = c[j] - 'A' + 10;
      else
        t = c[j] - '0';
      for (long long r = 0; r < (long long)4; r++) {
        tiv[n - 4 * j - 4 + r] = t % 2;
        t /= 2;
      }
    }
    q = 1;
    tiv[n] = 4;
    for (long long j = (long long)1; j < (long long)n + 1; j++) {
      if (tiv[j] == tiv[j - 1])
        q++;
      else {
        a.push_back(q);
        q = 1;
      }
    }
    ans = a.back();
    a.pop_back();
    while (!a.empty()) {
      ans = gcd(ans, a.back());
      a.pop_back();
    }
    b.push_back(ans);
    for (long long j = 0; j < (long long)n; j++) tiv[j] = 0;
  }
  ans = b.back();
  b.pop_back();
  while (!b.empty()) {
    ans = gcd(ans, b.back());
    b.pop_back();
  }
  cout << ans << endl;
  return 0;
}
