#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 5505;
int n;
int siz;
bitset<N> zmat[N];
string mat[N];
inline void in(int a) {
  int num;
  for (int i = 0; i < siz; i++) {
    if (isalpha(mat[a][i]))
      num = mat[a][i] - 'A' + 10;
    else
      num = mat[a][i] - '0';
    for (int j = 0; j < 4; j++) {
      zmat[a][4 * i + j] = (num & 1 << (3 - j));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  siz = n / 4;
  for (int i = 0; i < n; i++) {
    cin >> mat[i];
    in(i);
  }
  vector<int> fac;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) fac.push_back(i);
    if (n / i != i) fac.push_back(n / i);
  }
  sort(fac.rbegin(), fac.rend());
  bool flag = 0;
  for (int i = 0; i < fac.size(); i++) {
    bool ans = 1;
    for (int j = 0; j < n / fac[i]; j++) {
      for (int k = 0; k < n / fac[i]; k++) {
        for (int mi = 0; mi < n / fac[i]; mi++) {
          for (int mj = 0; mj < n / fac[i]; mj++) {
            if (zmat[j * fac[i] + mi][k * fac[i] + mj] !=
                zmat[j * fac[i]][k * fac[i]]) {
              ans = 0;
              break;
            }
          }
          if (!ans) break;
        }
        if (!ans) break;
      }
      if (!ans) break;
    }
    if (ans) {
      cout << fac[i] << "\n";
      flag = 1;
      break;
    }
  }
  if (!flag) cout << "1\n";
  return 0;
}
