#include <bits/stdc++.h>
using namespace std;
const int N = 52e2;
int n;
bool arr[N][N];
bool arrlol[N][N];
vector<int> solve() {
  vector<int> res;
  res.push_back(1);
  int copyN = n;
  for (int i = 2; i * i <= n; ++i) {
    if (copyN % i != 0) {
      continue;
    }
    int q = i;
    while (copyN % i == 0) {
      bool flag = true;
      for (int j = 0; j < n && flag; ++j) {
        for (int k = 0; k < n && flag; ++k) {
          flag &= arr[j][k] == arr[j][(k / q) * q];
        }
      }
      if (flag) {
        res.push_back(i);
      } else {
        break;
      }
      q *= i;
      copyN /= i;
    }
  }
  return res;
}
map<char, string> p;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  p['0'] = "0000";
  p['1'] = "0001";
  p['2'] = "0010";
  p['3'] = "0011";
  p['4'] = "0100";
  p['5'] = "0101";
  p['6'] = "0110";
  p['7'] = "0111";
  p['8'] = "1000";
  p['9'] = "1001";
  p['A'] = "1010";
  p['B'] = "1011";
  p['C'] = "1100";
  p['D'] = "1101";
  p['E'] = "1110";
  p['F'] = "1111";
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string str;
    cin >> str;
    for (int j = 0; j < n / 4; ++j) {
      string w = p[str[j]];
      for (int q = 0; q < 4; ++q) {
        arr[i][j * 4 + q] = w[q] == '1';
        arrlol[i][j * 4 + q] = w[q] == '1';
      }
    }
  }
  vector<int> arr1 = solve();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      arr[i][j] = arrlol[j][i];
    }
  }
  vector<int> arr2 = solve();
  vector<int> res;
  set_intersection(arr1.begin(), arr1.end(), arr2.begin(), arr2.end(),
                   back_inserter(res));
  int ans = 1;
  for (auto i : res) {
    ans *= i;
  }
  cout << ans << '\n';
  return 0;
}
