#include <bits/stdc++.h>
using namespace std;
const int maxn = 5205;
int n;
int Matrix[maxn][maxn];
char s[maxn];
int sum[maxn][maxn];
int is_digit(char c) {
  if (c >= '0' && c <= '9')
    return c - '0';
  else
    return c - 'A' + 10;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    memset(Matrix, 0, sizeof(Matrix));
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++) {
      scanf("%s", s + 1);
      for (int j = 1; j <= n / 4; j++) {
        int num = is_digit(s[j]);
        Matrix[i][(j - 1) * 4 + 1] = (num >> 3) & 1;
        Matrix[i][(j - 1) * 4 + 2] = (num >> 2) & 1;
        Matrix[i][(j - 1) * 4 + 3] = (num >> 1) & 1;
        Matrix[i][(j - 1) * 4 + 4] = (num >> 0) & 1;
      }
    }
    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] + Matrix[i][j];
      }
    }
    int flag1 = 1;
    for (int x = n; x >= 1 && flag1; x--) {
      if (n % x == 0) {
        int flag = 1;
        for (int i = 1; i <= n && flag; i += x) {
          for (int j = 1; j <= n && flag; j += x) {
            long long s = sum[i + x - 1][j + x - 1] - sum[i][j + x - 1] -
                          sum[i + x - 1][j] + sum[i][j];
            if (s != x * x && s != 0) {
              flag = 0;
              break;
            }
          }
        }
        if (flag) {
          printf("%d\n", x);
          flag1 = 0;
        }
      }
    }
  }
  return 0;
}
