#include <bits/stdc++.h>
using namespace std;
const int maxp = 22;
const long double EPS = 1e-18;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 5201;
int pref[N][N];
int box(int x, int y, int z) {
  x++;
  y++;
  return pref[x + z - 1][y + z - 1] - pref[x - 1][y + z - 1] -
         pref[x + z - 1][y - 1] + pref[x - 1][y - 1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int i, j;
  int arr[n][n];
  int k;
  for (i = 0; i < n; i++)
    for (j = 0; j < n / 4; j++) {
      char c;
      cin >> c;
      int num = 0;
      if (c <= '9')
        num += c - '0';
      else
        num += 10 + c - 'A';
      for (k = 0; k < 4; k++) {
        int bit = 0;
        if ((1 << (3 - k)) & num) bit++;
        arr[i][j * 4 + k] = bit;
      }
    }
  for (i = 1; i <= n; i++) {
    int sum = 0;
    for (j = 1; j <= n; j++) {
      sum += arr[i - 1][j - 1];
      pref[i][j] = pref[i - 1][j] + sum;
    }
  }
  int maxi = 1;
  for (k = 1; k * k <= n; k++) {
    if (n % k == 0) {
      int num = n / k;
      bool flag = true;
      for (i = 0; i < n / num; i += num)
        for (j = 0; j < n / num; j += num) {
          int sum = box(i, j, num);
          if (sum && sum != num * num) {
            flag = false;
            break;
          }
        }
      if (flag) {
        maxi = max(maxi, num);
      }
      flag = true;
      for (i = 0; i < n / k; i += k)
        for (j = 0; j < n / k; j += k) {
          int sum = box(i, j, k);
          if (sum && sum != k * k) {
            flag = false;
            break;
          }
        }
      if (flag) {
        maxi = max(maxi, k);
      }
    }
  }
  cout << maxi;
}
