#include <bits/stdc++.h>
using namespace std;
int a[5201][5201];
int dp[5201][5201];
void calc(int j, int u, int val) {
  vector<int> v(4);
  for (int i = 0; i < 4; i++) {
    v[i] = val % 2;
    val /= 2;
  }
  for (int i = 3; i >= 0; i--) {
    a[j][u] = v[i];
    u++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int u = 1;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] >= 65 && s[j] <= 70) {
        calc(i, u, s[j] - 'A' + 10);
      } else {
        calc(i, u, s[j] - '0');
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = a[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
    }
  }
  vector<int> v;
  for (int i = n; i >= 1; i--) {
    if (n % i == 0) v.push_back(i);
  }
  for (int i = 0; i < v.size(); i++) {
    int z = v[i] * v[i];
    int f = 0;
    for (int j = v[i]; j <= n; j += v[i]) {
      for (int k = v[i]; k <= n; k += v[i]) {
        int d = (dp[j][k] - dp[j - v[i]][k] - dp[j][k - v[i]] +
                 dp[j - v[i]][k - v[i]]);
        if (d != 0 && d != z) {
          f = 1;
          break;
        }
      }
      if (f == 1) break;
    }
    if (f == 1) {
      continue;
    } else {
      cout << v[i];
      return 0;
    }
  }
  return 0;
}
