#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<ll,ll>> ii;
#define pb push_back

int main(void)
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll n,t;
    cin >> n;
    ll ans = n;
    vector<vector<bool>> A(n,vector<bool>(n,false));

    for(int i = 0 ; i<n;i++)
    {   
        for(int j = 0;j<n/4;j++)
        {
            char c;
            cin >> c;
            if(isdigit(c))  t = c-'0';
            else    t = c - 'A'+10;
            for(int z = 0 ; z < 4; z++)
            {
                A[i][j*4+3-z]= t&1;
                t = t>>1;
            }
        }
    }

    for(int i = 0;i<n;i++)
    {
        t=1;
        for(int j = 1;j<n;j++)
        {
            if(A[i][j]!=A[i][j-1] || j>n)
            {
                ans=__gcd(ans,j-t);
                t=j;
            }
        }
    }
    for(int i = 0;i<n;i++)
    {
        t=1;
        for(int j = 1;j<n;j++)
        {
            if(A[j][i]!=A[j-1][i] || j>n)
            {
                ans=__gcd(ans,j-t);
                t=j;
            }
        }
    }

    cout << ans << endl;
    return 0;
}