#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long powm(long long base, long long exp, long long mod = 1000000007) {
  base %= mod;
  long long ans = 1;
  while (exp) {
    if (exp & 1LL) ans = (ans * base) % mod;
    exp >>= 1LL, base = (base * base) % mod;
  }
  return ans;
}
string m[5201];
int dp[5201][5201];
int n;
int gs(int r1, int c1, int r2, int c2) {
  return dp[r2][c2] - dp[r1][c2] - dp[r2][c1] + dp[r1][c1];
}
bool check(int x) {
  for (int i = 1; i <= n; i += x) {
    for (int j = 1; j <= n; j += x) {
      int t = gs(i, j, i + x - 1, j + x - 1);
      if (t != 0 && t != (x) * (x)) return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    m[i].push_back('*');
    for (int j = 0; j < s.length(); j++) {
      int x;
      if (s[j] <= '9')
        x = s[j] - '0';
      else
        x = 9 + s[j] - 'A' + 1;
      for (int r = 3; r >= 0; r--) {
        bool b = ((x & (1 << r)) != 0);
        m[i].push_back(b + '0');
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int cur = m[i][j] - '0';
      if (i == 1 && j == 1) {
        dp[i][j] = cur;
        continue;
      }
      if (i == 1) {
        dp[i][j] = dp[i][j - 1] + cur;
        continue;
      }
      if (j == 1) {
        dp[i][j] = dp[i - 1][j] + cur;
        continue;
      }
      dp[i][j] = cur + dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int j = n / i;
      if (check(i)) ans = max(ans, i);
      if (check(j)) ans = max(ans, j);
    }
  }
  cout << ans << '\n';
}
