#include <bits/stdc++.h>
using namespace std;
int s[5200][5200];
bool compress(int n, int N) {
  for (int i = 0; i < N; i += n) {
    for (int j = 0; j < N; j += n) {
      int a = (i - 1 >= 0 && j - 1 >= 0) ? s[i - 1][j - 1] : 0;
      int b = (i - 1 >= 0) ? s[i - 1][j + n - 1] : 0;
      int c = (j - 1 >= 0) ? s[i + n - 1][j - 1] : 0;
      int d = s[i + n - 1][j + n - 1];
      if (d - b - c + a != N * N) {
        return false;
      }
    }
  }
  return true;
}
int ToInt(char c) {
  if ('0' <= c && c <= '9') {
    return c - '0';
  }
  return c - 'A' + 10;
}
int main() {
  int N;
  cin >> N;
  getchar();
  char row[1305];
  for (int i = 0; i < N; ++i) {
    scanf("%s", row);
    for (int j = 0, t; j < N; ++j) {
      t = ((ToInt(row[j / 4]) >> (3 - j % 4)) & 1);
      if (i == 0 && j == 0) {
        s[i][j] = t;
      } else if (i == 0) {
        s[i][j] = s[i][j - 1] + t;
      } else if (j == 0) {
        s[i][j] = s[i - 1][j] + t;
      } else {
        s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + t;
      }
    }
  }
  int fac[5000], f = 0;
  for (int i = 2; i <= N; ++i) {
    if (N % i == 0) {
      fac[f++] = i;
    }
  }
  --f;
  while (f >= 0 && !compress(fac[f], N)) {
    --f;
  }
  cout << (f >= 0 ? fac[f] : 1) << endl;
  return 0;
}
