#include <bits/stdc++.h>
using namespace std;
int n, sm[5201][5201];
string s;
int to_digit(char ch) {
  if (isdigit(ch)) {
    return ch - '0';
  }
  return ch - 'A' + 10;
}
vector<int> get_factor(int x) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % x == 0) {
      ret.push_back(x);
      ret.push_back(n / x);
    }
  }
  return ret;
}
string hextobin(string s) {
  int k = 0, p = 1;
  while (s.size() > 0) {
    char ch = s.back();
    s.pop_back();
    k += p * (to_digit(ch));
    p *= 16;
  }
  s = "";
  while (k != 0) {
    p = k % 2;
    k /= 2;
    s += char(p + '0');
  }
  while (s.size() < n) {
    s += "0";
  }
  reverse(s.begin(), s.end());
  return s;
}
int get_sum(int x, int y, int len) {
  return sm[x][y] - sm[x - len][y] - sm[x][y - len] + sm[x - len][x - len];
}
void solve(int x) {
  int cnt = 0;
  for (int i = x; i <= n; i += x) {
    for (int j = x; j <= n; j += x) {
      int sum = get_sum(i, j, x);
      if (sum == 0 || sum == x * x) {
        cnt++;
      }
    }
  }
  if (cnt == (n / x) * (n / x)) {
    cout << x;
    exit(0);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    s = hextobin(s);
    int cnt = 0;
    for (int j = 1; j <= n; j++) {
      cnt += (s[j - 1] == '1');
      sm[i][j] = sm[i - 1][j] + cnt;
    }
  }
  vector<int> v = get_factor(n);
  sort(v.begin(), v.end(), greater<int>());
  for (int x : v) {
    solve(x);
  }
  cout << 1;
  return 0;
}
