/* Author : samarth
   Handle : ssg_13 */

//----------------------template begins--------------------------------//
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono;

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back //faster than pb
#define pb push_back 
#define Db(x) r+= '>' << #x << ':' << x << endl;
#define forn(i,n) for(ll i=0;i<n;i++)
#define rforn(i,n) for(ll i=n-1;i>=0;i--)
#define forne(i,n) for(ll i=1;i<=n;i++)
#define forse(i,s,e) for(ll i=s;i<e;i++)
#define rforse(i,s,e) for(ll i=e;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define PT palindromeTest	//Input - string, int, ll, l
#define GS generateSubsets	//Input - n		//Return - vector<vector<int>>
#define GP generatePermutations //Input - int n 	//Return - vector<vector<int>>
#define PF primeFactorization	//Input - ll	//Return - vector<ll>
#define nCr nCrModPFermat   //Input - n, r, p	//Return - nCr mod p
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(i) return pointer to ith index in ordered set


const ll MOD = 1000000007;
ll modpow(ll a,ll b,ll m=MOD) {a%=m;ll res=1;while(b){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
ll bpow(ll a, ll b) {ll res = 1;while(b){if(b&1)res=res*a;a=a*a;b>>=1;}return res;}
ll modinv(ll a){return modpow(a,MOD-2,MOD);}
void graph(vector<ll> adj[], ll m){ll x, y; forn(i, m){cin>>x>>y;adj[x-1].pb(y-1);adj[y-1].pb(x-1);}}
ll sum() { return 0; }
template<typename T, typename... Args>
auto sum(T a, Args... args) { return a + sum(args...); }

const ll INF=(ll)1e18;
const int MAXN = 200001;
//----------------------template ends--------------------------------//
string HexToBin(string hexdec) 
{ 
    long int i = 0; 
    string r="";
    while (hexdec[i]) { 
  
        switch (hexdec[i]) { 
        case '0': 
            r+= "0000"; 
            break; 
        case '1': 
            r+= "0001"; 
            break; 
        case '2': 
            r+= "0010"; 
            break; 
        case '3': 
            r+= "0011"; 
            break; 
        case '4': 
            r+= "0100"; 
            break; 
        case '5': 
            r+= "0101"; 
            break; 
        case '6': 
            r+= "0110"; 
            break; 
        case '7': 
            r+= "0111"; 
            break; 
        case '8': 
            r+= "1000"; 
            break; 
        case '9': 
            r+= "1001"; 
            break; 
        case 'A': 
        case 'a': 
            r+= "1010"; 
            break; 
        case 'B': 
        case 'b': 
            r+= "1011"; 
            break; 
        case 'C': 
        case 'c': 
            r+= "1100"; 
            break; 
        case 'D': 
        case 'd': 
            r+= "1101"; 
            break; 
        case 'E': 
        case 'e': 
            r+= "1110"; 
            break; 
        case 'F': 
        case 'f': 
            r+= "1111"; 
            break; 
        default: 
            r+= "\nInvalid hexadecimal digit ";
        } 
        i++; 
    } 
    return r;
} 
vector<vll> cnt;
bool check(ll n,ll x)
{
    bool ok=1;
    for(ll i=0;i<=n-x;i+=x)
    {
        for(ll j=0;j<=n-x;j+=x)
        {
            ll c1=(j>1)?cnt[i+x-1][j-1]:0;
            ll c2=(i>1)?cnt[i-1][j+x-1]:0;
            ll c3=(i>0 && j>0)?cnt[i-1][j-1]:0;
            ll val=cnt[i+x-1][j+x-1]-c1-c2+c3;
            if(val!=0 && val!=x*x) ok=0;
            if(!ok) break; 
        }
        if(!ok) break;
    }
    return ok;
}
int main()
{
fast;
cout<< fixed << setprecision(11);
cerr << fixed << setprecision(6);
auto start = high_resolution_clock::now();
ll T;
// cin>>T;
T=1;
while(T--)
{
    ll n;
    cin>>n;
    string a[n];
    forn(i,n) {string s;cin>>s;a[i]=HexToBin(s);}
    cnt.resize(n,vll(n));
    cnt[0][0]=(a[0][0]=='1');
    forne(i,n-1) {cnt[i][0]=cnt[i-1][0]+(a[i][0]=='1');cnt[0][i]=cnt[0][i-1]+(a[0][i]=='1');}
    forne(i,n-1) forn(j,n-1) cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+(a[i][j]=='1');
    ll ans=1;
    for(ll x=1;x*x<=n;x++) 
    {
        if(n%x==0)
        {
            if(check(n,x)) ans=max(ans,x);
            if(check(n,n/x)) ans=max(ans,n/x);
        }
    }
    cout<<ans<<'\n';
}
auto stop = high_resolution_clock::now(); 
auto duration = duration_cast<microseconds>(stop - start);
// r+= "Time taken by function: "
//          << duration.count() << " microseconds" << endl; 
}
