#include <bits/stdc++.h>
using namespace std;
const int INF = ~0U >> 1;
int n;
char ch;
map<char, string> s;
string row[5203];
long long sum[5203][5203];
vector<int> v;
int main() {
  s['0'] = "0000";
  s['1'] = "0001";
  s['2'] = "0010";
  s['3'] = "0011";
  s['4'] = "0100";
  s['5'] = "0101";
  s['6'] = "0110";
  s['7'] = "0111";
  s['8'] = "1000";
  s['9'] = "1001";
  s['A'] = "1010";
  s['B'] = "1011";
  s['C'] = "1100";
  s['D'] = "1101";
  s['E'] = "1110";
  s['F'] = "1111";
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n / 4; ++j) {
      cin >> ch;
      row[i] += s[ch];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +
                  ((char)row[i - 1][j - 1] - '0');
    }
  }
  for (int i = 1; i <= n / 2; ++i) {
    if (n % i == 0) {
      v.push_back(i);
      v.push_back(n / i);
    }
  }
  sort(v.begin(), v.end());
  int pos = 0;
  int ans = n;
  for (int i = 0; i < v.size(); ++i) {
    int s = v[i];
    bool flag = 0;
    for (int j = n / s; j <= n; j += (n / s)) {
      for (int k = n / s; k <= n; k += (n / s)) {
        long long t =
            (row[j / (n / s) - 1][k / (n / s) - 1] - '0') * (n / s) * (n / s);
        if (sum[j][k] - sum[j - n / s][k] - sum[j][k - n / s] +
                sum[j - n / s][k - n / s] !=
            t) {
          flag = 1;
          break;
        }
      }
      if (flag) break;
    }
    if (!flag) {
      ans = s;
      break;
    }
  }
  cout << n / ans << endl;
  return 0;
}
