#include <bits/stdc++.h>
using namespace std;
char s[5250][5250];
char a[5250][5250], row[5250][5250];
int sum[5250][5250];
int n;
int check(int x) {
  for (int i = 0; i < n / x; i++)
    for (int j = 0; j < n / x; j++) {
      int t1 = 0;
      t1 = sum[i * x + x][j * x + x];
      int t2 = 0;
      if (i * x - 1 >= 0) t2 = sum[i * x][j * x + x];
      int t3 = 0;
      if (j * x - 1 >= 0) t3 = sum[i * x + x][j * x];
      int t4 = 0;
      if (i * x - 1 >= 0 && j * x - 1 >= 0) t4 = sum[i * x][j * x];
      int t = t1 - t2 - t3 + t4;
      if (t != 0 && t != x * x) return 0;
    }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n / 4; j++) {
      int x;
      if (s[i][0] >= '0' && s[i][0] <= '9')
        x = s[i][0] - '0';
      else
        x = s[i][0] - 'A' + 10;
      a[i][j * 4 + 0] = x >> 3;
      a[i][j * 4 + 1] = (x >> 2) & 1;
      a[i][j * 4 + 2] = (x >> 1) & 1;
      a[i][j * 4 + 3] = x & 1;
    }
  for (int i = 0; i < n; i++) {
    row[i][0] = a[i][0];
    for (int j = 1; j < n; j++) row[i][j] = row[i][j - 1] + a[i][j];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      sum[i][j] =
          sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i - 1][j - 1];
    }
  int ans = 1;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      if (ans < i)
        if (check(i)) ans = max(ans, i);
      if (ans < n / i)
        if (check(n / i)) ans = n / i;
    }
  if (sum[n][n] == 0 || sum[n][n] == n * n) ans = n;
  cout << ans << endl;
  return 0;
}
