#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long expo(long long base, long long pow) {
  long long ans = 1;
  while (pow != 0) {
    if (pow & 1 == 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base *= base;
    base %= mod;
    pow /= 2;
  }
  return ans;
}
long long inv(long long x) { return expo(x, mod - 2); }
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int M = 2e5 + 5;
int arr[5203][5203], brr[5203][5203];
char ex[2000];
int n;
void process(int x, int y, char xa) {
  int num = 0;
  if (xa >= '0' && xa <= '9') {
    num = (xa - '0');
  } else {
    num = (xa - 'A' + 10);
  }
  while (num > 0) {
    arr[x][y] = (num % 2);
    y--;
    num /= 2;
  }
}
bool check(int k) {
  if (n % k) return 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int i1 = i / k + (((i % k) != 0) ? 1 : 0);
      int j1 = j / k + (((j % k) != 0) ? 1 : 0);
      if (brr[i1][j1] != -1 && brr[i1][j1] != arr[i][j]) {
        return 0;
      }
      brr[i1][j1] = arr[i][j];
    }
  }
  return 1;
}
int main() {
  scanf("%d", &(n));
  int colL = n / 4;
  int re = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", &ex);
    re = 4;
    for (int j = 0; j < colL; j++) {
      process(i, re, ex[j]);
      re += 4;
    }
  }
  vector<int> vec;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      vec.push_back(i);
      if (i * i != n) {
        vec.push_back(n / i);
      }
    }
  }
  sort(vec.begin(), vec.end());
  int lo = 1, hi = vec.size() - 1;
  int ans = 0;
  while (lo <= hi) {
    memset(brr, -1, sizeof(brr));
    int mid = (lo + hi) / 2;
    memset(brr, -1, sizeof(brr));
    if (check(vec[mid])) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << vec[ans];
}
