#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
string make(string hexdec) {
  int i = 0;
  int sz = (int)hexdec.size();
  string Y = "";
  while (i < sz) {
    switch (hexdec[i]) {
      case '0':
        Y += "0000";
        break;
      case '1':
        Y += "0001";
        break;
      case '2':
        Y += "0010";
        break;
      case '3':
        Y += "0011";
        break;
      case '4':
        Y += "0100";
        break;
      case '5':
        Y += "0101";
        break;
      case '6':
        Y += "0110";
        break;
      case '7':
        Y += "0111";
        break;
      case '8':
        Y += "1000";
        break;
      case '9':
        Y += "1001";
        break;
      case 'A':
      case 'a':
        Y += "1010";
        break;
      case 'B':
      case 'b':
        Y += "1011";
        break;
      case 'C':
      case 'c':
        Y += "1100";
        break;
      case 'D':
      case 'd':
        Y += "1101";
        break;
      case 'E':
      case 'e':
        Y += "1110";
        break;
      case 'F':
      case 'f':
        Y += "1111";
        break;
    }
    i++;
  }
  return Y;
}
int n, ans, p;
bool ok;
vector<int> v;
char s[5400];
string S[5400];
char f[5400][5400];
char g[5400][5400];
int fix[5400];
int main() {
  std::ios::sync_with_stdio(false);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    S[i] = make(s);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      f[i + 1][j + 1] = S[i][j];
    }
  }
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (n / i != i) {
        v.push_back(n / i);
      }
    }
  }
  sort(v.rbegin(), v.rend());
  memset(g, '*', sizeof g);
  int c = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    ok = 1;
    if (fix[v[i]] == 1) continue;
    if (c == 32) {
      printf("%d", 1);
      return 0;
    }
    for (int j = 1; j <= n; j++) {
      for (int o = 1; o <= n; o++) {
        int x = (int)ceil((double)j / (double)v[i]);
        int y = (int)ceil((double)o / double(v[i]));
        if (g[x][y] != f[j][o] && g[x][y] != '*') {
          ok = 0;
          break;
        } else
          g[x][y] = f[j][o];
      }
      if (ok == 0) {
        break;
      }
    }
    if (ok == 1) {
      printf("%d", v[i]);
      return 0;
    }
    for (int j = 2; j <= v[i]; j++) {
      if (v[i] % j == 0) {
        fix[j] = 1;
      }
    }
    memset(g, '*', sizeof g);
  }
}
