#include <bits/stdc++.h>
using namespace std;
string conv(char r) {
  switch (r) {
    case '0':
      return "0000";
      break;
    case '1':
      return "0001";
      break;
    case '2':
      return "0010";
      break;
    case '3':
      return "0011";
      break;
    case '4':
      return "0100";
      break;
    case '5':
      return "0101";
      break;
    case '6':
      return "0110";
      break;
    case '7':
      return "0111";
      break;
    case '8':
      return "1000";
      break;
    case '9':
      return "1001";
      break;
    case 'A':
      return "1010";
      break;
    case 'B':
      return "1011";
      break;
    case 'C':
      return "1100";
      break;
    case 'D':
      return "1101";
      break;
    case 'E':
      return "1110";
      break;
    case 'F':
      return "1111";
      break;
  }
}
string encod(string s) {
  string ss = "";
  for (int i = 0; i < s.size(); i++) {
    ss += conv(s[i]);
  }
  return ss;
}
bool check2(string s, int x) {
  char fir;
  for (int ii = 0; ii < s.size(); ii++) {
    if (ii % x == 0) {
      fir = s[ii];
    } else {
      if (fir != s[ii]) {
        return 0;
      }
    }
  }
  return 1;
}
bool check(int x, vector<string> arr) {
  string first;
  for (int i = 0; i < arr.size(); i++) {
    if (i % x == 0) {
      first = arr[i];
      string ss = encod(first);
      if (!check2(ss, x)) return 0;
    } else {
      if (first != arr[i]) return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<string> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<int> div;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      if (i == 4) continue;
      div.push_back(i);
    }
  }
  sort(div.begin(), div.end());
  long long res = -1;
  int S = 0, E = div.size() - 1, M;
  while (S <= E) {
    M = (S + E) / 2;
    if (check(div[M], arr)) {
      S = M + 1;
      res = max((long long)div[M], res);
    } else
      E = M - 1;
  }
  cout << res << endl;
  return 0;
}
