#include <bits/stdc++.h>
using namespace std;
int modexpo(int x, int p) {
  int res = 1;
  x = x % 1000000007;
  while (p) {
    if (p % 2) res = res * x;
    p >>= 1;
    x = x * x % 1000000007;
    res %= 1000000007;
  }
  return res;
}
int max(int a, int b) { return (a > b ? a : b); }
int min(int a, int b) { return (a < b ? a : b); }
struct edge {
  int u, v, w;
  edge(int a, int b, int c) {
    u = a;
    v = b;
    w = c;
  }
};
struct compare {
  bool operator()(const edge a, const edge b) const {
    if (a.u == b.u) {
      if (a.v == b.v) {
        return a.w < b.w;
      }
      return a.v < b.v;
    }
    return a.u < b.u;
  }
};
string hexToBin(char c) {
  if (c == '0') {
    return "0000";
  }
  if (c == '1') {
    return "0001";
  }
  if (c == '2') {
    return "0010";
  }
  if (c == '3') {
    return "0011";
  }
  if (c == '4') {
    return "0100";
  }
  if (c == '5') {
    return "0101";
  }
  if (c == '6') {
    return "0110";
  }
  if (c == '7') {
    return "0111";
  }
  if (c == '8') {
    return "1000";
  }
  if (c == '9') {
    return "1001";
  }
  if (c == 'A') {
    return "1010";
  }
  if (c == 'B') {
    return "1011";
  }
  if (c == 'C') {
    return "1100";
  }
  if (c == 'D') {
    return "1101";
  }
  if (c == 'E') {
    return "1110";
  }
  if (c == 'F') {
    return "1111";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int dp[n + 1][n + 1], arr[n + 1][n + 1];
  memset(dp, 0, sizeof(dp));
  memset(arr, -1, sizeof(arr));
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int x = s.length();
    for (int j = 0; j < x; j++) {
      string cur = hexToBin(s[j]);
      arr[i][(4 * j) + 1] = (int)(cur[0] - '0');
      arr[i][(4 * j) + 2] = (int)(cur[1] - '0');
      arr[i][(4 * j) + 3] = (int)(cur[2] - '0');
      arr[i][(4 * j) + 4] = (int)(cur[3] - '0');
    }
  }
  for (int i = 1; i <= n; i++) {
    arr[i][0] = -1;
    for (int j = 1; j <= n; j++) {
      if (arr[i][j] == arr[i][j - 1]) {
        dp[i][j] = dp[i][j - 1] + 1;
      } else {
        dp[i][j] = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (arr[i - 1][j] == arr[i][j]) {
        dp[i][j] += dp[i - 1][j];
      }
    }
  }
  vector<int> v;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int x = i;
      int y = n / i;
      if (x == y) {
        v.push_back(x);
      } else {
        v.push_back(x);
        v.push_back(y);
      }
    }
  }
  sort(v.begin(), v.end());
  int res = 0;
  for (int k : v) {
    int flag = 0;
    for (int i = k; i <= n && !flag; i += k) {
      for (int j = k; j <= n && !flag; j += k) {
        if ((dp[i][j] % (k * k)) != 0) {
          flag = 1;
        }
      }
    }
    if (!flag) {
      res = max(res, k);
    }
  }
  cout << res << "\n";
}
