#include <bits/stdc++.h>
using namespace std;
string all[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
                "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
vector<string> v;
int n;
void check(int x) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      long long a = (i + 1) / x + ((i + 1) % x != 0),
                b = (j + 1) / x + ((j + 1) % x != 0);
      if (v[i][j] != v[a * x - 1][b * x - 1]) {
        return;
      }
    }
  }
  cout << x;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n / 4; j++) {
      char b;
      cin >> b;
      if (b > 58) {
        v[i] += all[b - 'A' + 10];
      } else {
        v[i] += all[b - '0'];
      }
    }
  }
  int i = n;
  set<int> x;
  int xx = 1;
  for (int i = 1; i <= n; i++) {
    if (i == n || v[0][i] != v[0][i - 1]) {
      x.insert(xx);
    } else {
      xx++;
    }
  }
  if (x.size() == 1) check(*x.begin());
  cout << 1;
}
