#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
  long long int res = 1;
  while (b != 0) {
    if (b & 1) {
      res = (res * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res;
}
bool compi(long long int a, long long int b) { return a > b; }
void solve() {
  long long int n;
  cin >> n;
  char a[n + 1][n + 1];
  map<char, string> mp;
  mp['0'] = "0000";
  mp['1'] = "0001";
  mp['2'] = "0010";
  mp['3'] = "0011";
  mp['4'] = "0100";
  mp['5'] = "0101";
  mp['6'] = "0110";
  mp['7'] = "0111";
  mp['8'] = "1000";
  mp['9'] = "1001";
  mp['A'] = "1010";
  mp['B'] = "1011";
  mp['C'] = "1100";
  mp['D'] = "1101";
  mp['E'] = "1110";
  mp['F'] = "1111";
  for (long long int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (long long int j = 0; j < s.size(); j++) {
      string t = mp[s[j]];
      long long int z = j * 4;
      for (long long int k = 0; k < 4; k++) {
        z++;
        a[i][z] = t[k];
      }
    }
  }
  vector<long long int> fac;
  for (long long int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      fac.push_back(i);
      fac.push_back(n / i);
    }
  }
  long long int mx = 0;
  sort(fac.begin(), fac.end(), compi);
  long long int p[n + 1][n + 1];
  memset(p, 0, sizeof(p));
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j < n; j++) {
      p[i][j] = (long long int)(a[i][j] - '0');
    }
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + p[i][j];
    }
  }
  for (long long int i = 0; i < fac.size(); i++) {
    long long int x = fac[i];
    bool f = true;
    for (long long int j = x; j <= n; j += x) {
      for (long long int k = x; k <= n; k += x) {
        long long int ans =
            p[j][k] - p[j - x][k] - p[j][k - x] + p[j - x][k - x];
        if (ans == 0 || ans == x * x) continue;
        f = false;
        break;
      }
      if (!f) break;
    }
    if (f) {
      mx = max(mx, x);
      break;
    }
  }
  cout << mx << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) solve();
  return 0;
}
