#include <bits/stdc++.h>
using namespace std;
map<char, string> we;
int n, x;
int a[5201][5201];
int pass(int bx) {
  int div = n / bx, aa, bb, cc, dd;
  int d = div * div, b = bx * bx, f = 0;
  for (int i = 0; i < div; i++) {
    for (int j = 0; j < div; j++) {
      aa = (i + 1) * bx - 1;
      bb = (j + 1) * bx - 1;
      cc = aa - bx;
      dd = bb - bx;
      int t = a[aa][bb];
      if (cc >= 0) t -= a[cc][bb];
      if (dd >= 0) t -= a[aa][dd];
      if (cc >= 0 && dd >= 0) t += a[cc][dd];
      if (t == 0 || t == b) f++;
    }
  }
  if (f == d)
    return 0;
  else
    return 1;
}
int main() {
  we['0'] = "0000";
  we['1'] = "0001";
  we['2'] = "0010";
  we['3'] = "0011";
  we['4'] = "0100";
  we['5'] = "0101";
  we['6'] = "0110";
  we['7'] = "0111";
  we['8'] = "1000";
  we['9'] = "1001";
  we['A'] = "1010";
  we['B'] = "1011";
  we['C'] = "1100";
  we['D'] = "1101";
  we['E'] = "1110";
  we['F'] = "1111";
  scanf("%d", &n);
  vector<int> v;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) v.push_back(i);
    v.push_back(n / i);
  }
  x = n / 4;
  char c;
  for (int i = 0; i < n; i++) {
    scanf("%c", &c);
    for (int j = 0; j < n; j += 4) {
      scanf("%c", &c);
      string s = we[c];
      a[i][j] = 1;
      a[i][j + 1] = 1;
      a[i][j + 2] = 1;
      a[i][j + 3] = 1;
      if (s[0] == '0') a[i][j] = 0;
      if (s[1] == '0') a[i][j + 1] = 0;
      if (s[2] == '0') a[i][j + 2] = 0;
      if (s[3] == '0') a[i][j + 3] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != 0) a[i][j] = a[i][j] + a[i - 1][j];
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[j][i] += a[j][i - 1];
    }
  }
  int cnt = 0;
  sort(v.begin(), v.end());
  while (cnt < v.size() && pass(v[cnt]) == 0) {
    cnt++;
  }
  cnt--;
  printf("%d", v[cnt]);
  return 0;
}
