#include <bits/stdc++.h>
using namespace std;
int toBin(char c) {
  if (c < 'A') {
    return c - '0';
  } else {
    return c - 'A' + 10;
  }
}
vector<int> get_factors(int n) {
  vector<int> ans;
  for (int i = n; i >= 1; --i)
    if (n % i == 0) ans.push_back(i);
  return ans;
}
bitset<5200> a[5200];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n / 4; j++) {
      char c;
      cin >> c;
      int cb = toBin(c);
      a[i][j * 4] = cb & 1;
      a[i][j * 4 + 1] = (cb >> 1) & 1;
      a[i][j * 4 + 2] = (cb >> 2) & 1;
      a[i][j * 4 + 3] = (cb >> 3) & 1;
    }
  }
  vector<int> facs = get_factors(n);
  for (auto& x : facs) {
    bool flg = 1;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        if (a[i][j] != a[i / x][j / x]) {
          flg = 0;
          break;
        }
    if (flg) {
      cout << x;
      return 0;
    }
  }
  return 0;
}
