#include <bits/stdc++.h>
using namespace std;
void build(map<char, string> &mp) {
  mp['0'] = "0000";
  mp['1'] = "0001";
  mp['2'] = "0010";
  mp['3'] = "0011";
  mp['4'] = "0100";
  mp['5'] = "0101";
  mp['6'] = "0110";
  mp['7'] = "0111";
  mp['8'] = "1000";
  mp['9'] = "1001";
  mp['A'] = "1010";
  mp['B'] = "1011";
  mp['C'] = "1100";
  mp['D'] = "1101";
  mp['E'] = "1110";
  mp['F'] = "1111";
}
bool check(vector<vector<int>> &arr, int n, int x) {
  for (int i = 0; i < n / x; i++) {
    for (int j = 0; j < n / x; j++) {
      for (int u = i * x; u < (i + 1) * x; u++) {
        for (int v = j * x; v < (j + 1) * x; v++)
          if (arr[u][v] != arr[i * x][j * x]) return 0;
      }
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    int n, ans, x;
    scanf("%d", &n);
    char str[n];
    map<char, string> mp;
    vector<vector<int>> arr(n, vector<int>(n));
    build(mp);
    char ch;
    for (long long i = 0; i < n; i++) {
      scanf("%s", str);
      for (long long i = 0; i < n / 4; i++) {
        for (long long j = 0; j < 4; j++)
          arr[i][4 * i + j] = mp[str[i]][j] - '0';
      }
    }
    vector<int> v;
    for (int i = 1; i * i <= n; i++)
      if (n % i == 0) {
        v.push_back(i);
        if (i != n / i) v.push_back(n / i);
      }
    sort(v.begin(), v.end());
    int l = 0, r = n - 1, mid;
    for (int i = v.size() - 1; i >= 0; i--) {
      if (check(arr, n, v[i])) {
        ans = v[i];
        break;
      }
    }
    printf("%d", ans);
  }
}
