#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n; cin >> n;
int f[n][n]; char c;
for (int i=0;i<=n-1;i++)
{
        for (int j=0;j<=n/4-1;j++){
            scanf(" %c", &c);
            int x = '0' <= c && c <= '9' ? c - '0' : c - 'A' + 10;
            f[i][j*4] = (x & 8) > 0;
            f[i][j*4+1] = (x & 4) > 0;
            f[i][j*4+2] = (x & 2) > 0;
            f[i][j*4+3] = (x & 1) > 0;
        }
}
int kq=n;
int i=0;
        int a=0;
    for (int j=1;j<=n-1;j++){
        if (f[i][j]!=f[i][j-1]) {kq=__gcd(kq,j-a);a=j;}
    }
    kq=__gcd(kq,n-a);

cout << kq;
}

