#include <bits/stdc++.h>
using namespace std;
vector<long long> factors;
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
int mask[16][4] = {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1},
                   {0, 1, 0, 0}, {0, 1, 0, 1}, {0, 1, 1, 0}, {0, 1, 1, 1},
                   {1, 0, 0, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}, {1, 0, 1, 1},
                   {1, 1, 0, 0}, {1, 1, 0, 1}, {1, 1, 1, 0}, {1, 1, 1, 1}};
long long mod(long long a, long long m) {
  return (a + (abs(a) / m) * m + m) % m;
}
vector<int> prime;
void getp(int n) {
  long long s = sqrt(n) + 1;
  for (int i = 2; i <= s; ++i) {
    if (n / i == 0) {
      prime.push_back(i);
    }
  }
  if (prime.empty()) prime.push_back(n);
}
bool check(vector<vector<int>>& m, int k) {
  for (int f = 0; f < m.size(); ++f) {
    for (int i = 0; i < m.size() / k; ++i) {
      for (int j = 0; j < k; ++j) {
        if (m[f][i * (m.size() / k) + j] != m[f][i * (m.size() / k)])
          return false;
      }
    }
  }
  for (int f = 0; f < m.size(); ++f) {
    for (int i = 0; i < m.size() / k; ++i) {
      for (int j = 0; j < k; ++j) {
        if (m[i * (m.size() / k) + j][f] != m[i * (m.size() / k)][f])
          return false;
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> mtrx(n, vector<int>(n, 0));
  for (int i = 0; i < n; ++i) {
    string st;
    cin >> st;
    for (int j = 0; j < st.size(); ++j) {
      if (st[j] >= '0' && st[j] <= '9') {
        mtrx[i][j * 4] = mask[st[j] - '0'][0];
        mtrx[i][j * 4 + 1] = mask[st[j] - '0'][1];
        mtrx[i][j * 4 + 2] = mask[st[j] - '0'][2];
        mtrx[i][j * 4 + 3] = mask[st[j] - '0'][3];
      } else {
        mtrx[i][j * 4] = mask[st[j] - 'A' + 10][0];
        mtrx[i][j * 4 + 1] = mask[st[j] - 'A' + 10][1];
        mtrx[i][j * 4 + 2] = mask[st[j] - 'A' + 10][2];
        mtrx[i][j * 4 + 3] = mask[st[j] - 'A' + 10][3];
      }
    }
  }
  getp(n);
  vector<bool> ch(prime.size(), false);
  int res = 1;
  for (int i = 0; i < prime.size(); ++i) {
    ch[i] = check(mtrx, prime[i]);
    if (ch[i]) res *= i;
  }
  cout << res;
  return 0;
}
