#include <bits/stdc++.h>
using namespace std;
string kkk(char s) {
  if (s == '0') return "0000";
  if (s == '1') return "0001";
  if (s == '2') return "0010";
  if (s == '3') return "0011";
  if (s == '4') return "0100";
  if (s == '5') return "0101";
  if (s == '6') return "0110";
  if (s == '7') return "0111";
  if (s == '8') return "1000";
  if (s == '9') return "1001";
  if (s == 'A') return "1010";
  if (s == 'B') return "1011";
  if (s == 'C') return "1100";
  if (s == 'D') return "1101";
  if (s == 'E') return "1110";
  if (s == 'F') return "1111";
}
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  int g = x % y;
  while (g != 0) {
    x = y;
    y = g;
    g = x % y;
  }
  return y;
}
int main() {
  int n;
  cin >> n;
  string ditu[5300];
  for (int i = 0; i < n; i++) cin >> ditu[i];
  string hang = kkk(ditu[0][0]);
  for (int i = 1; i < n / 4; i++) {
    hang += kkk(ditu[0][i]);
  }
  string jjj;
  string lie = "", lie2 = "";
  for (int i = 0; i < n; i++) {
    jjj = kkk(ditu[i][0]);
    lie += jjj[0];
    lie2 += jjj[n - 1];
  }
  int len = 1;
  for (int i = 0; i < hang.size(); i++) {
    for (int j = i + 1; j < hang.size(); j++) {
      if (hang[j] == hang[j - 1])
        len++;
      else
        break;
    }
    break;
  }
  len = gcd(len, n);
  int len2 = 1;
  for (int i = 0; i < lie.size(); i++) {
    for (int j = i + 1; j < lie.size(); j++)
      if (lie[j] == lie[j - 1])
        len2++;
      else
        break;
    break;
  }
  len2 = gcd(len2, n);
  len = gcd(len, len2);
  int f = 0;
  for (int i = 0; i < len - 1; i++)
    if (ditu[i + 1] != ditu[i]) {
      f = 1;
      break;
    }
  if (f == 0)
    cout << len << endl;
  else
    cout << 1 << endl;
}
