#include <bits/stdc++.h>
using namespace std;
int fuc(char c) {
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5;
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  if (c == 'A') return 10;
  if (c == 'B') return 11;
  if (c == 'C') return 12;
  if (c == 'D') return 13;
  if (c == 'E') return 14;
  if (c == 'F') return 15;
  cout << "OHSHIT!" << endl;
  return 666;
}
int n;
string s;
bool g[5500][5500];
int b[5500][5500];
vector<int> v;
bool chk(int x) {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (b[(i + x - 1) / x][(j + x - 1) / x] == -1) {
        b[(i + x - 1) / x][(j + x - 1) / x] = g[i][j];
      } else {
        if (b[(i + x - 1) / x][(j + x - 1) / x] != g[i][j]) {
          return false;
        }
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      int x = fuc(s[j]), y = j * 4 + 4;
      while (y > j * 4) {
        g[i][y] = x % 2;
        x /= 2;
        y--;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
    }
  }
  int l = 0, r = v.size() - 1, m, ans;
  while (l <= r) {
    memset(b, -1, sizeof(b));
    m = (l + r) / 2;
    if (chk(v[m])) {
      ans = m;
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  cout << v[ans] << endl;
  return 0;
}
