#include <bits/stdc++.h>
void File_IO() {}
using namespace std;
map<char, string> bin;
int n;
char mat[6500][6500];
bool valid(int bit) {
  for (int i = 0; i < n; i += bit) {
    for (int j = 0; j < n; j += bit) {
      if (mat[i][j] != mat[i % bit][j % bit]) return false;
    }
  }
  return true;
}
int main() {
  File_IO();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  bin['0'] = "0000";
  bin['1'] = "0001";
  bin['2'] = "0010";
  bin['3'] = "0011";
  bin['4'] = "0100";
  bin['5'] = "0101";
  bin['6'] = "0110";
  bin['7'] = "0111";
  bin['8'] = "1000";
  bin['9'] = "1001";
  bin['A'] = "1010";
  bin['B'] = "1011";
  bin['C'] = "1100";
  bin['D'] = "1101";
  bin['E'] = "1110";
  bin['F'] = "1111";
  char ch;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x = 0;
    for (int j = 0; j < n / 4; j++) {
      cin >> ch;
      for (int k = 0; k < bin[ch].size(); k++) {
        mat[i][x++] = bin[ch][k];
      }
    }
  }
  int maxi = 1;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (valid(n / i)) {
        maxi = max(maxi, i);
      }
      if (valid(i)) {
        maxi = max(maxi, n / i);
      }
    }
  }
  cout << maxi << endl;
}
