#include <bits/stdc++.h>
using namespace std;
int n, ans, a[5203], top = 0;
bool board[5203][5203];
char c;
bool ok(int x) {
  bool start = false, sample;
  for (int i = 1; i <= n / x; i++)
    for (int j = 1; j <= n / x; j++)
      for (int c = (i - 1) * x + 1; c < i * x; c++)
        for (int r = (j - 1) * x + 1; r < j * x; r++) {
          if (start == false) {
            start = true;
            sample = board[c][r];
          } else if (board[c][r] != sample)
            return false;
        }
  return true;
}
void binSearch(int l, int r) {
  for (int i = r; i >= l; i--)
    if (ok(a[i])) {
      ans = a[i];
      break;
    }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    if (!(n % i)) a[++top] = i;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n / 4; j++) {
      cin >> c;
      int val;
      if ('0' <= c && c <= '9')
        val = c - '0';
      else
        val = c - 'A' + 10;
      board[i][(j - 1) * 4 + 1] = (val >> 3) & 1;
      board[i][(j - 1) * 4 + 2] = (val >> 2) & 1;
      board[i][(j - 1) * 4 + 3] = (val >> 1) & 1;
      board[i][(j - 1) * 4 + 4] = val & 1;
    }
  binSearch(1, top);
  cout << ans;
  return 0;
}
