#include <bits/stdc++.h>
using namespace std;
int a[5205][5205];
bool check(int i, int j, int k) {
  int act =
      a[i + k][j + k] - a[i - 1][j + k] - a[i + k][j - 1] + a[i - 1][j - 1];
  if (act == k * k || act == 0) return 1;
  return 0;
}
vector<int> divv[5205];
int main() {
  ios_base::sync_with_stdio(false);
  char x;
  int i, j, nr, ind2, n, k, ans;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n / 4; j++) {
      cin >> x;
      if (x >= '0' && x <= '9')
        nr = x - '0';
      else
        nr = x - 'A' + 10;
      for (k = 1; k <= 4; k++) {
        ind2 = (j - 1) * 4 + k;
        a[i][ind2] = (nr & 8);
        a[i][ind2] += a[i - 1][ind2] + a[i][ind2 - 1] - a[i - 1][ind2 - 1];
        nr = nr << 1;
      }
    }
  }
  for (i = 2; i * i <= n; i++) {
    for (j = i; j <= n; j += i) divv[j].push_back(i);
  }
  ans = n;
  for (i = 1; i <= n; i += ans) {
    for (j = 1; j <= n; j += ans) {
      for (k = divv[ans].size() - 1; k >= 0; k--) {
        if (check(i, j, divv[ans][k])) break;
      }
      if (k == -1) {
        cout << 1 << '\n';
        return 0;
      }
      ans = divv[ans][k];
    }
  }
  cout << ans << '\n';
  return 0;
}
