#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = 3.141592653589793238462;
const int MAXN = 5200;
int n, arr[MAXN][MAXN];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int hexToDec(char c) {
  int dec = 0;
  if ('0' <= c && '9' >= c)
    dec = (int)c - '0';
  else if ('A' <= c && 'F' >= c)
    dec = (int)c - 'A' + 10;
  return dec;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < n / 4; j++) {
      int dec = hexToDec(s[j]);
      for (int k = 0; k < 4; k++) {
        if (dec & (1 << k)) arr[i][3 - k] = 1;
      }
    }
  }
  int x = n;
  for (int i = 0; i < n; i++) {
    int len = 1;
    for (int j = 1; j < n; j++) {
      if (arr[i][j] == arr[i][j - 1])
        len++;
      else {
        x = gcd(x, len);
        len = 1;
        j++;
      }
    }
  }
  for (int j = 0; j < n; j++) {
    int len = 1;
    for (int i = 1; i < n; i++) {
      if (arr[i][j] == arr[i - 1][j])
        len++;
      else {
        x = gcd(x, len);
        len = 1;
        i++;
      }
    }
  }
  printf("%d\n", x);
}
