#include <bits/stdc++.h>
using namespace std;
const int maxn = 5210;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn], pre[maxn][maxn];
int n;
char s[maxn][maxn];
void change(int x) {
  for (int i = 0; i <= n / 4 - 1; ++i) {
    int c = s[x][i] - 'A' + 9 + 1;
    if (s[x][i] >= '0' && s[x][i] <= '9') c = s[x][i] - '0';
    for (int j = 4; j >= 1; j--) {
      a[x][i * 4 + j] = c & 1;
      c >>= 1;
    }
  }
  return;
}
int main() {
  cin >> n;
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    change(i);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1] + a[i][j];
    }
  }
  bool ok = 1;
  for (int i = 1; i <= n / 2; i++) {
    if (n % i != 0) continue;
    ok = 1;
    int I = n / i;
    for (int j = 1; j <= n / i; ++j) {
      for (int k = 1; k <= n / i; ++k) {
        int x = pre[j * i][k * i] - pre[j * i][(k - 1) * i] -
                pre[(j - 1) * i][k * i] + pre[(j - 1) * i][(k - 1) * i];
        if (x != 0 && x != I * I) ok = 0;
      }
    }
    if (ok) {
      ans = I;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}
