#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 5205;
int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }
int n;
string s;
int f(int i) {
  if (s[i] <= '9' && s[i] >= '0')
    return s[i] - '0';
  else
    return s[i] - 'A' + 10;
}
bool x[maxn][maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      int m = f(j);
      for (int k = 4; k >= 1; k--) {
        x[i][j * 4 + k] = m & 1;
        m /= 2;
      }
    }
  }
  int ans = n;
  for (int i = 1; i <= n; i++) {
    int a1 = n;
    int last = 1;
    for (int j = 2; j <= n; j++) {
      if (x[i][j] != x[i][j - 1]) {
        a1 = gcd(a1, gcd(j - last, n - j + 1));
        last = j;
        if (a1 == 1) break;
      }
    }
    a1 = gcd(a1, gcd(last, n - last));
    ans = gcd(ans, a1);
    if (ans == 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    int a1 = n;
    int last = 1;
    for (int j = 2; j <= n; j++) {
      if (x[j][i] != x[j - 1][i]) {
        a1 = gcd(a1, gcd(i - last, n - i + 1));
        last = i;
        if (a1 == 1) break;
      }
    }
    a1 = gcd(a1, gcd(last, n - last));
    ans = gcd(ans, a1);
    if (ans == 1) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
