#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  scanf("%lld", &n);
  string str[n], fuck[n];
  long long int sum[n][n];
  for (long long int i = 0; i < n; i++) cin >> str[i];
  for (long long int i = 0; i < n; i++) {
    string to_add = "";
    for (long long int j = 0; j < (long long int)str[i].size(); j++) {
      long long int num;
      if (str[i][j] >= '0' && str[i][j] <= '9') {
        num = str[i][j] - '0';
      } else {
        num = str[i][j] - 'A' + 10;
      }
      string temp = "";
      while (num) {
        temp += (num % 2) + '0';
        num /= 2;
      }
      while ((long long int)temp.size() < 4) temp += '0';
      reverse(temp.begin(), temp.end());
      to_add += temp;
    }
    for (long long int j = 0; j < (long long int)to_add.size(); j++) {
      fuck[i][j] = to_add[j];
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (fuck[i][0] == '0')
      sum[i][0] = 0;
    else
      sum[i][0] = 1;
    for (long long int j = 1; j < n; j++) {
      if (fuck[i][j] == '0')
        sum[i][j] = sum[i][j - 1];
      else
        sum[i][j] = sum[i][j - 1] + 1;
    }
  }
  for (long long int j = 0; j < n; j++) {
    for (long long int i = 1; i < n; i++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  for (long long int x = n; x >= 1; x--) {
    if (n % x == 0) {
      bool ok = true;
      long long int r1 = 0;
      for (long long int r2 = x - 1; r2 < n && ok; r2 += x) {
        long long int c1 = 0;
        for (long long int c2 = x - 1; c2 < n && ok; c2 += x) {
          long long int Ans = sum[r2][c2];
          if (c1 > 0) Ans -= sum[r2][c1 - 1];
          if (r1 > 0) Ans -= sum[r1 - 1][c2];
          if (r1 > 0 && c1 > 0) Ans += sum[r1 - 1][c1 - 1];
          if (Ans == x * x || Ans == 0) {
            c1 += x;
          } else {
            ok = false;
          }
        }
        r1 += x;
      }
      if (ok) {
        cout << x << "\n";
        exit(0);
      }
    }
  }
  return 0;
}
