#include <bits/stdc++.h>
using namespace std;
const int nmax = 5200;
bool A[nmax + 5][nmax + 5];
int n, maxi;
int Z[nmax + 5][nmax + 5], U[nmax + 5][nmax + 5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char C[nmax + 5];
    cin >> C + 1;
    for (int j = 1; j <= n / 4; j++) {
      int x;
      if (C[j] >= 'A' && C[j] <= 'F')
        x = C[j] - 'A' + 10;
      else
        x = C[j] - '0';
      for (int k = 0; k < 4; k++) {
        A[i][4 * j + 3 - k] = x % 2;
        x /= 2;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (A[i][j] == 1)
        U[i][j] = min(A[i - 1][j], min(A[i][j - 1], A[i - 1][j - 1])) + 1;
      else
        Z[i][j] = min(Z[i - 1][j], min(Z[i][j - 1], Z[i - 1][j - 1])) + 1;
  maxi = 1;
  bool ok;
  for (int x = 2; x <= n; x++) {
    ok = 1;
    if (n % x != 0) continue;
    for (int i = x; i <= n; i += x)
      for (int j = x; j <= n; j += x)
        if (Z[i][j] < x && U[i][j] < x) ok = 0;
    if (ok) maxi = x;
  }
  cout << maxi;
  return 0;
}
