#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b)
    return gcd(b, a % b);
  else
    return a;
}
const int maxn = 5201;
int n, a[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int num;
  char c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n / 4; j++) {
      cin >> c;
      if (c > 64)
        num = c - 'A' + 10;
      else
        num = c - '0';
      for (int k = 3; k >= 0; k--) {
        a[i][j] = (num >> k) % 2;
      }
    }
  }
  int cont = 1;
  vector<int> p;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (a[i][j] != a[i][j - 1]) {
        p.push_back(cont);
        cont = 1;
      }
      cont++;
    }
  }
  for (int j = 0; j < n; j++) {
    for (int i = 1; i < n; i++) {
      if (a[i][j] != a[i - 1][j]) {
        p.push_back(cont);
        cont = 1;
      }
      cont++;
    }
  }
  int ans = p[0];
  for (int i = 1; i < p.size(); i++) {
    ans = gcd(ans, p[i]);
  }
  cout << ans << "\n";
}
