#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, inf = 1e18, mod = 1e9 + 7;
int n, m, k, l, r, ans;
int a[N], b[N];
vector<pair<char, int> > lol;
vector<int> v;
string q;
void parse(char t) {
  string s;
  int x;
  if (t >= '0' && t <= '9')
    x = t - '0';
  else {
    x = t - 'A';
    x += 10;
  }
  while (x) {
    if (x % 2 == 1)
      s += '1';
    else
      s += '0';
    x /= 2;
  }
  while (s.size() < 4) s += '0';
  reverse(s.begin(), s.end());
  q += s;
}
bool res[N];
int p = 1;
vector<int> var;
vector<int> suf[N];
void f(int y) {
  vector<int> pref;
  pref.push_back(0);
  string s = q;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == '1')
      pref.push_back(pref[pref.size() - 1] + 1);
    else
      pref.push_back(pref[pref.size() - 1]);
  suf[p] = pref;
  p++;
  for (auto j : var) {
    if (res[j] == 0) continue;
    for (int i = 0; i + j < pref.size(); i += j)
      if (!(pref[j + i] - pref[i] == j || pref[j + i] - pref[i] == 0))
        res[j] = 0;
  }
  for (auto j : var) {
    if (res[j] == 0) continue;
    int poc, coc;
    int modi = y % j;
    int kekus = y / j;
    if (modi == 0) {
      poc = j * (y / j - 1) + 1;
      coc = y - 1;
    } else {
      poc = j * (y / j) + 1;
      coc = y - 1;
    }
    if (coc - poc != j) continue;
    for (int t = poc; t <= coc; t++)
      for (int i = 0; i + j < pref.size(); i += j)
        if (!(pref[j + i] - pref[i] == suf[t][j + i] - suf[t][i])) res[j] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  char t;
  for (int i = 1; i <= n; i++)
    if (n % i == 0) {
      res[i] = 1;
      var.push_back(i);
    }
  for (int i = 0; i < n; i++) {
    q = "";
    for (int j = 0; j < n / 4; j++) {
      cin >> t;
      parse(t);
    }
    f(i + 1);
  }
  for (int i = n; i >= 1; i--)
    if (res[i]) {
      cout << i;
      return 0;
    }
}
