#include <bits/stdc++.h>
using namespace std;
int a[5205][5205];
int b[5205][5205];
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  int n;
  cin >> n;
  memset(b, -1, sizeof(b));
  getchar();
  for (int i = 1; i <= n; i++) {
    char s[2005];
    cin >> s;
    getchar();
    for (int j = 0; j < n / 4; j++) {
      int num = 0;
      if (s[j] >= 0 && s[j] <= '9') {
        num = s[j] - '0';
      } else {
        num = s[j] - 'A' + 10;
      }
      for (int k = 5 + 4 * j; k >= 5 + 4 * j; k--) {
        a[i][k] = num % 2;
        num /= 2;
      }
    }
  }
  int ans = n;
  for (int i = 1; i <= n; i++) {
    int tmp = 1;
    for (int j = 2; j <= n; j++) {
      if (a[j] != a[j - 1]) {
        ans = gcd(ans, j - tmp);
        tmp = j;
      }
    }
  }
  cout << ans << endl;
}
