#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int N = 5501;
bool a[N][N];
int n;
void parse(int g, int pos, char c) {
  int val;
  if (c <= '9')
    val = c - '0';
  else
    val = c - 'A' + 10;
  for (int i = 0; i < 4; i++)
    if ((val >> i) & 1)
      a[g][pos + 3 - i] = 1;
    else
      a[g][pos + 3 - i] = 0;
}
bool check(int x) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[(i - 1) / x + 1][(j - 1) / x + 1] != a[i][j]) {
        return 0;
      }
  return 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j + j + j + j <= n; j++) {
      char x;
      cin >> x;
      parse(i, (j - 1) * 4 + 1, x);
    }
  }
  int cans = 1;
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      if (i > cans && check(i)) cans = i;
      if (n / i > cans && check(n / i)) cans = n / i;
    }
  cout << cans;
  return 0;
}
