#include <bits/stdc++.h>
using namespace std;
vector<int> v[101000];
int a[5500][5500], n, cnt[10];
int chk(int c) {
  for (int x = 1; x <= n; x += c)
    for (int y = 1; y <= n; y += c) {
      for (int i = 0; i < c; i++)
        for (int j = 0; j < c; j++)
          if (a[x][y] != a[x + i][y + j]) {
            return 0;
          }
    }
  return 1;
}
int bs() {
  int l = 0, r = v[n].size() - 1;
  while ((r - l) > 1) {
    int mid = (l + r) / 2;
    if (chk(v[n][mid]))
      l = mid;
    else
      r = mid;
  }
  if (chk(v[n][r])) return v[n][r];
  return v[n][l];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i <= 10000; i++)
    for (int j = i; j <= 10000; j += i) v[j].push_back(i);
  string s;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 0; j < (n / 4); j++) {
      if (s[j] <= 57) {
        for (int k = 3; k >= 0; k--) {
          a[i][j * 4 + (4 - k)] = (((s[j] - 48) & (1 << k)) > 0);
          cnt[a[i][j]]++;
        }
      } else {
        for (int k = 3; k >= 0; k--) {
          a[i][j * 4 + (4 - k)] = (((s[j] - 55) & (1 << k)) > 0);
          cnt[a[i][j]]++;
        }
      }
    }
  }
  if (cnt[0] == n * n || cnt[1] == n * n) {
    cout << n << endl;
    return 0;
  }
  cout << bs() << endl;
}
