#include <bits/stdc++.h>
using namespace std;
const int N = 5200 + 5, mod = 1e9 + 7, Mod = 998244353;
int A[N][N];
vector<int> divi;
int bin(int n) {
  int ans = 0, k;
  for (int c = 7; c >= 0; c--) {
    ans *= 10;
    k = n >> c;
    if (k & 1) ans++;
  }
  return ans;
}
int saghf(int a, int b) { return ((a / b) + ((a % b > 0) ? 1 : 0)); }
bool check(int a, int n) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (A[i][j] != A[saghf(i, a)][saghf(j, a)]) return false;
  return true;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char c[n / 4];
    scanf("%s", c);
    for (int j = 1; j <= n / 4; j++) {
      int t = 0;
      if (c[j - 1] >= 'A' && c[j - 1] <= 'F')
        t = c[j - 1] - 'A' + 10;
      else
        t = c[j - 1] - '0';
      int a = bin(t);
      for (int k = 0; k < 4; k++) {
        A[i][4 * j - k] = a % 10;
        a /= 10;
      }
    }
  }
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      divi.push_back(i);
      if (i != n / i) divi.push_back(n / i);
    }
  int ans = 1;
  for (auto u : divi)
    if (check(u, n)) ans = max(ans, u);
  printf("%d", ans);
}
