#include <bits/stdc++.h>
using namespace std;
const int N = 5200;
char s[N][N + 1];
vector<vector<int> > cnt(N, vector<int>(N));
vector<string> v(72);
void f() {
  string ss = "0123456789ABCDEF";
  for (int i = 0; i < 16; i++) {
    string tt = "";
    int x = i;
    while (x > 0) {
      tt += to_string(x % 2);
      x /= 2;
    }
    reverse(tt.begin(), tt.end());
    while (int(tt.size()) < 4) {
      tt = "0" + tt;
    }
    v[ss[i]] = tt;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  f();
  char t[n / 4 + 1];
  for (int i = 0; i < n; i++) {
    scanf("%s", t);
    int idx = 0;
    for (int j = 0; j < n / 4; j++) {
      for (int k = 0; k < 4; k++) {
        s[i][idx++] = v[t[j]][k];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cnt[i][j] += (s[i][j] - '0');
      if (i > 0) {
        cnt[i][j] += cnt[i - 1][j];
      }
      if (j > 0) {
        cnt[i][j] += cnt[i][j - 1];
      }
      if (i > 0 && j > 0) {
        cnt[i][j] -= cnt[i - 1][j - 1];
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    if (n % i == 0) {
      bool ok = true;
      for (int j = i - 1; j < n && ok; j += i) {
        for (int k = i - 1; k < n; k += i) {
          int x = cnt[j][k];
          if (j - i > 0) {
            x -= cnt[j - i - 1][k];
          }
          if (k - i > 0) {
            x -= cnt[j][k - i - 1];
          }
          if (j - i > 0 && k - i > 0) {
            x += cnt[j - i - 1][k - i - 1];
          }
          if (x > 0 && x < i * i) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        printf("%d\n", i);
        return 0;
      }
    }
  }
}
