#include <bits/stdc++.h>
using namespace std;
int mar[5205][5205];
int main() {
  int n;
  scanf("%d", &n);
  char tmp;
  for (int i = 1; i <= n; i++) {
    getchar();
    for (int j = 1; j <= n; j += 4) {
      tmp = getchar();
      int t;
      if (tmp > '9') {
        t = tmp - 'A';
      } else {
        t = tmp - '0';
      }
      for (int k = 0; k < 4; k++) {
        mar[i][j + k] = (t >> (3 - k)) & 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      mar[i][j] += mar[i - 1][j] + mar[i][j - 1] - mar[i - 1][j - 1];
    }
  }
  for (int i = n; i >= 1; i--) {
    if (n % i) {
      continue;
    }
    bool flag = 1;
    for (int j = 1; j * i <= n; j++) {
      for (int k = 1; k * i <= n; k++) {
        int tmp = mar[i * j][i * k] - mar[i * j][i * (k - 1)] -
                  mar[i * (j - 1)][i * k] + mar[i * (j - 1)][i * (k - 1)];
        flag &= (tmp == 0 || tmp == i * i);
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
