#include <bits/stdc++.h>
using namespace std;
int A[5210][1310];
inline bool getA(int x, int y) {
  int a = y / 4;
  int b = (1 << (3 - y % 4));
  int c = A[x][a];
  return (c & b);
}
bool check(int n, int i) {
  int x = n / i;
  for (int j = 0; j < i; j++) {
    for (int k = 0; k < i; k++) {
      bool block = getA(j * x, k * x);
      for (int l = 0; l < x; l++) {
        for (int m = 0; m < x; m++) {
          if (block != getA(j * x + l, k * x + m)) return false;
        }
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  register char c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n / 4; j++) {
      do c = getchar();
      while (c == '\n');
      if (c > '9')
        A[i][j] = 10 + c - 'A';
      else
        A[i][j] = c - '0';
    }
  }
  for (int i = 1; i <= n; i++) {
    if ((n % i) == 0) {
      int x = n / i;
      if (check(n, i)) {
        cout << x << endl;
        return 0;
      }
    }
  }
  return 0;
}
