#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x;
  cin >> n;
  string s;
  vector<vector<bool>> a(n, vector<bool>(n, false));
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      if (isalpha(s[j])) {
        x = s[j] - 'A' + 10;
      } else {
        x = s[j] - '0';
      }
      for (int k = 3; k >= 0; k--) {
        a[i][j * 4 + k] = (x % 2 == 1);
        x /= 2;
      }
    }
  }
  int ans = 0;
  vector<int> div;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      div.push_back(i);
      if (i * i != n) {
        div.push_back(n / i);
      }
    }
  }
  sort(div.begin(), div.end());
  int m;
  bool valid;
  for (int ii = div.size() - 1; ii >= 0; ii--) {
    m = div[ii];
    valid = true;
    for (int i = 0; valid && i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (a[i][j] != a[m * (i / m)][m * (j / m)]) {
          valid = false;
          break;
        }
      }
    }
    if (valid) {
      cout << m << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
