#include <bits/stdc++.h>
using namespace std;
char a[5555][5555];
long long n, ans = 1;
string ikk[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
                "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
void chek(long long son) {
  int ok = 1;
  set<string> s;
  long long farq = n / son;
  int sana = 0;
  for (long long ii = (0); ii < (son); ii++)
    for (long long jj = (0); jj < (son); jj++) {
      string now;
      for (long long i = (0); i < (n / son); i++) {
        for (long long j = (0); j < (n / son); j++) {
          now += a[i + ii * farq][j + jj * farq];
        }
      }
      sana++;
      s.insert(now);
      if (s.size() > 1) return;
    }
  ans = max(ans, son);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  set<char> st;
  for (long long i = (0); i < (n); i++) {
    string s;
    cin >> s;
    int now = 0;
    for (auto x : s) {
      int son;
      if (x >= '0' && x <= '9')
        son = x - '0';
      else
        son = x - 'A' + 10;
      for (long long q = (0); q < (4); q++) {
        a[i][now++] = ikk[son][q];
        st.insert(ikk[son][q]);
      }
    }
  }
  for (long long i = (n + 1 - 1); i >= (1); i--)
    if (n % i == 0) chek(i);
  cout << ans;
  return 0;
}
