#include <bits/stdc++.h>
using namespace std;
int a[5210][5210], n;
int main() {
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / 4; j++) {
      char ch1;
      int x1;
      scanf("%c", &ch1);
      if ((ch1 >= 'A') && (ch1 <= 'F'))
        x1 = (ch1 - 'A') + 10;
      else
        x1 = (ch1 - '0');
      int off = (j - 1) * 4;
      a[i][off + 1] = x1 / 8;
      a[i][off + 2] = (x1 / 4) % 2;
      a[i][off + 3] = (x1 / 2) % 2;
      a[i][off + 4] = x1 % 2;
    }
    scanf("\n");
  }
  for (int t = 2; t <= n; t++) {
    if (n % t == 0) {
      bool ok = 1;
      for (int i = 1; i <= n / t; i += t) {
        for (int j = 1; j <= n / t; j += t) {
          for (int ii = 1; ii <= t; ii++)
            for (int jj = 1; jj <= t; jj++)
              if (a[i + ii - 1][j + jj - 1] != a[i][j]) {
                ok = false;
                break;
              }
          if (!ok) break;
        }
        if (!ok) break;
      }
      if (ok) {
        cout << n / t << endl;
        return 0;
      }
    }
    while (n % t == 0) {
      n /= t;
    }
  }
  cout << 1 << endl;
  return 0;
}
