#include <bits/stdc++.h>
using namespace std;
const long long int INF = 10000000000;
const long long int mod = 1000000007;
long long int MOD(long long int a, long long int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
long long int max3(long long int a, long long int b, long long int c) {
  return max(c, max(a, b));
}
long long int min3(long long int a, long long int b, long long int c) {
  return min(a, min(b, c));
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long int power1(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
long long int logg(long long int a) {
  long long int x = 0;
  while (a > 1) {
    x++;
    a /= 2;
  }
  return x;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int abso(long long int x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
long long int ceiling(long long int a, long long int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
long long int modinv(long long int x) { return power1(x, mod - 2); }
vector<vector<int>> mat;
int n;
bool check(int x) {
  vector<vector<int>> temp(n / x + 1);
  for (int j = 1; j <= (n / x); j++) {
    temp[j].resize(n / x + 1, -1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (temp[ceiling(i, x)][ceiling(j, x)] == -1) {
        temp[ceiling(i, x)][ceiling(j, x)] = mat[i][j];
      } else {
        if (temp[ceiling(i, x)][ceiling(j, x)] != mat[i][j]) {
          return false;
        }
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  mat.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    mat[i].resize(n + 1);
    string str;
    cin >> str;
    for (int j = 1; j <= n / 4; j++) {
      char tp = str[j - 1];
      int y = 0;
      if (tp <= '9' && tp >= '0') {
        y = tp - '0';
      } else {
        y = tp - 'A' + 10;
      }
      for (int k = 0; k < 4; k++) {
        mat[i][j * 4 - k] = y % 2;
        y = y / 2;
      }
    }
  }
  int mx = 1;
  vector<int> divis;
  if (check(n)) {
    cout << n;
    return 0;
  }
  divis.push_back(n);
  for (int x = 2; x * x <= n; x++) {
    if (n % x == 0) {
      divis.push_back(x);
      if (x != (n / x)) {
        divis.push_back(n / x);
      }
    }
  }
  divis.push_back(1);
  sort(divis.begin(), divis.end());
  int beg = 0;
  int end = (int)divis.size() - 1;
  int mid = (beg + end) / 2;
  while (beg <= end) {
    int mid = (beg + end) / 2;
    bool c1 = check(divis[mid]);
    bool c2 = check(divis[mid + 1]);
    if (c1 && !c2) {
      cout << divis[mid];
      return 0;
    } else {
      if (c1) {
        beg = mid + 1;
      } else {
        end = mid - 1;
      }
    }
  }
  cout << divis[mid];
}
