#include <bits/stdc++.h>
using namespace std;
const int N = 5204;
const long long MOD = 1e9 + 7LL;
char a[N][N];
vector<long long> divv;
vector<long long> gdiv;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  string s;
  cin >> n;
  int t;
  int k = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    k = 0;
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] <= '9' && s[j] >= '0')
        t = (s[j] - '0');
      else
        t = (s[j] - 'A') + 10;
      for (int k = 0; k < 4; ++k) {
        if ((t & (1 << k)))
          a[i][j + k + 1] = '1';
        else
          a[i][j + k + 1] = '0';
      }
    }
  }
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      divv.push_back(i);
      if (i * i != n) divv.push_back(n / i);
    }
  }
  int at;
  for (int i = 0; i < divv.size(); ++i) {
    at = 0;
    for (int j = 0; j < divv.size(); ++j) {
      if (i == j) continue;
      if (divv[i] % divv[j] == 0) at = 1;
    }
    if (!at) gdiv.push_back(divv[i]);
  }
  for (auto c : gdiv) {
    bool bad = true;
    int d = n / c;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (a[(i + d - 1) / d][(j + d - 1) / d] != a[i][j]) {
          bad = false;
          goto prox;
        }
      }
    }
    cout << d << "\n";
    return 0;
  prox:;
  }
  cout << 1 << "\n";
  return 0;
}
