#include <bits/stdc++.h>
using namespace std;

#define elif else if
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=a-1;i>=n;i--)
#define repp(i,a,n) for (ll i=a;i<=n;i++)
#define pper(i,a,n) for (ll i=a;i>=n;i--)
#define pf(x) printf("%.15f\n", x)
#define fix(x,y) cout<<fixed<<setprecision(y)<<x;
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("bridges.in","r",stdin);freopen("bridges.out","w",stdout)
#define bs(s,n) binary_search(s.begin(),s.end(),n)
#define be(s) s.begin(),s.end()
#define sz(s) s.size()
#define pii pair<long long,long long>
#define in insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ld pi = 3.1415926535897932384626433;
const ll M = 1e9+7;

char ch[6000][6000];
ll n,t,p,l,r;
string s;
vector<ll> v;

void f(ll i, string s){
    const std::string hex(s);
    std::istringstream stream(hex);
    int dec;
    stream >> std::hex >> dec;
    ll zz=0;
    while(dec)
    {
        zz++;
        ch[i][n-zz+1]=char('0'+dec%2);
        dec=dec/2;
    }
    repp(j,zz+1,n)
        ch[i][n-j+1]='0';
}

int main(){
    IOS;
    cin>>n;
    repp(i,1,n){
        cin>>s;
        f(i,s);
    }
   /* bool q=false;
    repp(i,1,n){
        if(q)
            break;
        repp(j,1,i){
            if(ch[i][j]!=ch[1][1]){
                    q=true;
                break;
            }
            if(ch[j][i]!=ch[1][1]){
                    q=true;
                break;
            }
        }
        if(!q)
        t=i;
    }
    q=true;
    repp(i,t+1,n)
        repp(j,1,n){
            if(ch[i][j]!=ch[1][t]){
                q=false;
                break;
            }
            if(ch[j][i]!=ch[1][t]){
                q=false;
                break;
            }
        }
        if(q)
            return cout<<t,0;*/
    repp(i,1,n){
        t=p=0;
        repp(j,1,n){
            if(ch[i][j]!=ch[i][j-1]){
                if(j-1!=0){
                    v.pb(j-1-t);
                    t=j-1;
                }
            }
            if(ch[j][i]!=ch[j-1][i]){
                if(j-1!=0){
                    //cout<<p<<" "<<j-1<<"   "<<j-1-p<<endl;
                    v.pb(j-1-p);
                    p=j-1;
                }
            }
        }
    }
    if(sz(v)==0)
        return cout<<n,0;
    t=n;
    for(auto i:v)
        t=__gcd(i,t);
    cout<<t;
}
