#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9, MN = 5210;
int n;
string board[MN];
int doit(char c, int bit) {
  int d = (isalpha(c) ? c - 'A' + 10 : c - '0');
  return (d >> bit) & 1;
}
int get(int i, int j) { return doit(board[i][j / 4], 3 - j % 4); }
bool check(int x) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (get(i, j) != get(i / x, j / x)) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> board[i];
  vector<int> divisors;
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      divisors.push_back(i);
      if (i * i != n) divisors.push_back(n / i);
    }
  sort(divisors.begin(), divisors.end());
  int lo = 0, hi = (int)divisors.size() - 1;
  if (check(divisors[hi])) {
    cout << divisors[hi] << '\n';
    return 0;
  }
  while (hi - lo > 1) {
    int mi = (hi + lo) / 2;
    if (check(divisors[mi]))
      lo = mi;
    else
      hi = mi;
  }
  cout << divisors[lo] << '\n';
  return 0;
}
