#include <bits/stdc++.h>
using namespace std;
string s[5400];
int n, mx = 1, sum;
int pre[5400][5400], pree[5400][5400];
string a[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
              "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
bool ok(int x) {
  bool yes = 1;
  for (int i = 1; i + x - 1 <= n; i += x)
    for (int j = 1; j + x - 1 <= n; j += x)
      yes &= (pree[i + x - 1][j] - pre[i - 1][j] == x ||
              pree[i + x - 1][j] - pre[i - 1][j] == 0);
  return yes;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string t, b = "0";
    cin >> t;
    for (int j = 0; j < n / 4; j++) {
      if (t[j] >= 'A' && t[j] <= 'F')
        b += a[t[j] - 'A' + 10];
      else
        b += a[t[j] - '0'];
    }
    s[i] = b;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) pre[i][j] = pre[i][j - 1] + (s[i][j] == '1');
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) pree[i][j] = pre[i - 1][j] + pre[i][j];
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (ok(i)) mx = max(mx, i);
      if (ok(n / i)) mx = max(mx, n / i);
    }
  }
  cout << mx;
  return 0;
}
