#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int maxn = 5200 + 10;
char s[maxn];
bool a[maxn][maxn];
int sum[maxn][maxn];
int main() {
  int n;
  map<char, int> Map;
  scanf("%d", &n);
  for (char i = '0'; i <= '9'; i++) Map[i] = i - '0';
  for (char i = 'A'; i <= 'E'; i++) Map[i] = i - 'A' + 10;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    int tmp = 0;
    for (int j = 1; j <= n / 4; j++)
      for (int k = 3; k >= 0; k--) {
        tmp++;
        if (Map[s[j]] & (1 << k)) a[i][tmp] = 1;
      }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
  for (int ans = n; ans >= 1; ans--)
    if (n % ans == 0) {
      int cnt = ans * ans;
      bool flag = 1;
      for (int i = 1; i <= n && flag; i += ans) {
        for (int j = 1; j <= n && flag; j += ans) {
          int ii = i + ans - 1, jj = j + ans - 1;
          int tmp =
              sum[ii][jj] - sum[i - 1][jj] - sum[ii][j - 1] + sum[i - 1][j - 1];
          if (tmp == 0 || tmp == cnt)
            ;
          else
            flag = 0;
        }
      }
      if (flag) {
        printf("%d\n", ans);
        break;
      }
    }
  return 0;
}
