#include <bits/stdc++.h>
using namespace std;
string hex_to_bin(string);
int n;
string s[5205];
int d[5205][5205];
void sol(int x) {
  for (int i = x; i <= n; i += x)
    for (int j = x; j <= n; j += x) {
      int p = d[i][j] - d[i - x][j] - d[i][j - x] + d[i - x][j - x];
      if (p == 0 || p == x * x)
        continue;
      else
        return;
    }
  cout << x;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int k = 1; k <= n; k++) s[k][0] = '%';
  for (int k = 1; k <= n; k++) {
    string s1;
    cin >> s1;
    s[k] = hex_to_bin(s1);
  }
  set<int> st;
  for (int k = 1; k * k <= n; k++)
    if (n % k == 0) {
      st.insert(-k);
      st.insert(-n / k);
    }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++) {
      d[k][i] = d[k - 1][i] + d[k][i - 1] - d[k - 1][i - 1];
      if (s[k][i] == '1') d[k][i]++;
    }
  while (!st.empty()) {
    if (st.size() == 1) {
      cout << 1;
      return 0;
    }
    int p = (*st.begin());
    p *= (-1);
    sol(p);
    st.erase(st.begin());
  }
  return 0;
}
string hex_to_bin(string s1) {
  string out;
  for (int i = 0; i < s1.size(); i++) {
    uint8_t n;
    if (s1[i] <= '9' && s1[i] >= '0')
      n = s1[i] - '0';
    else
      n = 10 + s1[i] - 'A';
    for (int8_t j = 3; j >= 0; --j) out.push_back((n & (1 << j)) ? '1' : '0');
  }
  return out;
}
