#include <bits/stdc++.h>
using namespace std;
long long const mod = 1e9 + 7;
long long power(long long x, long long y, long long mod = 2e18) {
  long long ans = 1;
  x %= mod;
  while (y) {
    if (y & 1) ans = (x * ans) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
vector<long long> v;
long long n;
string second[5401];
string see(char a) {
  if (a == '0') return "0000";
  if (a == '1') return "0001";
  if (a == '2') return "0010";
  if (a == '3') return "0011";
  if (a == '4') return "0100";
  if (a == '5') return "0101";
  if (a == '6') return "0110";
  if (a == '7') return "0111";
  if (a == '8') return "1000";
  if (a == '9') return "1001";
  if (a == 'A') return "1010";
  if (a == 'B') return "1011";
  if (a == 'C') return "1100";
  if (a == 'D') return "1101";
  if (a == 'E') return "1110";
  if (a == 'F') return "1111";
  return "1111";
}
void fn(long long i) {
  bool first = 1;
  for (long long j = 0; j < n; j += i) {
    for (long long k = j; k < j + i - 1; k++) {
      if (second[k] != second[k + 1]) {
        first = 0;
        break;
      }
    }
  }
  if (first) v.push_back(i);
}
bool check(long long x) {
  if (x == 2) {
    for (long long i = 0; i < n; i += 2) {
      for (long long j = 0; j < n / 4; j++) {
        if (second[i][j] != '0' && second[i][j] != 'C' && second[i][j] != 'F' &&
            second[i][j] != '3')
          return 0;
      }
    }
    return 1;
  }
  if (x == 4) {
    for (long long i = 0; i < n; i += 2) {
      for (long long j = 0; j < n / 4; j++) {
        if (second[i][j] != '0' && second[i][j] != 'F') return 0;
      }
    }
    return 1;
  }
  for (long long i = 0; i < n; i += x) {
    string p = "";
    for (long long w = 0; w < n / 4; w++) {
      p += see(second[i][w]);
    }
    for (long long j = 0; j < n; j += x) {
      for (long long k = j; k < j + x - 1; k++) {
        if (p[k] != p[k + 1]) {
          return 0;
        }
      }
    }
  }
  return 1;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> second[i];
  }
  long long ans = 1;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      fn(n / i);
      if (i * i != n) {
        fn(i);
      }
    }
  }
  v.push_back(n);
  for (auto x : v) {
    if (check(x)) ans = max(x, ans);
  }
  cout << ans << endl;
  return 0;
}
