#include <bits/stdc++.h>
#pragma G++ optimize(2)
using namespace std;
const int N = 5205;
int n, f[N][N][2], ans = 1, c[N], cnt;
bool a[N][N];
void rd(int i, int st) {
  char in = 0;
  int x;
  while (!(('0' <= in && in <= '9') || ('A' <= in && in <= 'F')))
    scanf("%c", &in);
  if ('0' <= in && in <= '9') x = in - '0';
  if ('A' <= in && in <= 'F') x = in - 'A' + 10;
  for (int j = st + 3; j >= st; j--) {
    a[i][j] = x & 1;
    x >>= 1;
  }
}
void FJ() {
  for (int i = 2; i <= n; i++)
    if (n % i == 0) c[++cnt] = i;
}
bool check(int x) {
  for (int i = x; i <= n; i += x)
    for (int j = 1; j <= n; j++) {
      if (f[i][j][1] < x) return 0;
      if (j % x == 0 && f[i][j][0] < x) return 0;
    }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j += 4) rd(i, j);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      f[i][j][0] = f[i][j][1] = 1;
      if (a[i][j - 1] == a[i][j]) f[i][j][0] = f[i][j - 1][0] + 1;
      if (a[i - 1][j] == a[i][j]) f[i][j][1] = f[i - 1][j][1] + 1;
    }
  FJ();
  int l = 1, r = cnt;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(c[mid])) {
      ans = c[mid];
      l = mid + 1;
    } else
      r = mid - 1;
  }
  printf("%d", ans);
  return 0;
}
