#include <bits/stdc++.h>
using namespace std;
long long modulo(long long num, long long MOD = 1000000007) {
  return ((num % MOD) + MOD) % MOD;
}
long long power(long long b, long long e, long long MOD = 1000000007) {
  long long ans = 1;
  while (e) {
    if (e % 2) ans = (ans * b) % MOD;
    b = (b * b) % MOD;
    e /= 2;
  }
  return ans;
}
long long inv(long long num, long long MOD = 1000000007) {
  return power(modulo(num), MOD - 2, MOD);
}
const long long N = 5205;
string hex(char c) {
  if (c == 'A') return "1010";
  if (c == 'B') return "1011";
  if (c == 'C') return "1100";
  if (c == 'D') return "1101";
  if (c == 'E') return "1110";
  if (c == 'F') return "1111";
  if (c == '1') return "0001";
  if (c == '2') return "0010";
  if (c == '3') return "0011";
  if (c == '4') return "0100";
  if (c == '5') return "0101";
  if (c == '6') return "0110";
  if (c == '7') return "0111";
  if (c == '8') return "1000";
  if (c == '9') return "1001";
  if (c == '0') return "0000";
}
long long pre[5205][5205];
void solve() {
  long long n;
  cin >> n;
  string s, arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> s;
    for (long long j = 0; j < (long long)s.length(); j++) {
      arr[i] += hex(s[j]);
    }
  }
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < N; j++) {
      pre[i][j] = 0;
    }
  }
  pre[1][1] = (arr[0][0] == '1');
  for (long long i = 2; i <= n; i++)
    pre[1][i] = pre[1][i - 1] + (arr[0][i - 1] == '1');
  for (long long i = 2; i <= n; i++)
    pre[i][1] = pre[i - 1][1] + (arr[i - 1][0] == '1');
  for (long long i = 2; i <= n; i++) {
    for (long long j = 2; j <= n; j++) {
      pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1] +
                  (arr[i - 1][j - 1] == '1');
    }
  }
  bool flag = 1;
  long long ans = 1;
  for (long long i = n; i >= 2; i--) {
    if (n % i == 0) {
      long long req = n / i;
      if (req == 1) continue;
      flag = 1;
      for (long long j = i; j <= n; j += i) {
        for (long long k = i; k <= n; k += i) {
          long long sm =
              pre[j][k] - pre[j - i][k] - pre[j][k - i] + pre[j - i][k - i];
          if (sm == req * req || sm == 0) continue;
          flag = 0;
        }
      }
      if (flag == 1) {
        ans = i;
        break;
      }
    }
  }
  cout << ans;
}
signed main() { solve(); }
