                                        #include <bits/stdc++.h>

                                        typedef long long ll;
                                        typedef  double ld;
                                        #define rep(i,a,n) for(ll i=(a); i<(n); i++)
                                        #define per(i,a,n) for(ll i=(n-1); i>=(a); i--)
                                        #define F first
                                        #define S second
                                        #define maxx(a,b) a=max(a,b)
                                        #define minn(a,b) a=min(a,b)
                                        #define db(x) cerr<<#x<<" = "<<x<<endl
                                        #define N 1111111
                                        #define mod 998244353
                                        #define rt return

                                        using namespace std;

                                        char a[5555][5555];

                                        string ikk[]={"0000","0001","0010","0011","0100","0101","0110","0111","1000",
                                        "1001","1010","1011","1100","1101","1110","1111"};

                                        int main(){
                                            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

                                            //freopen("Ulug'bek","r",stdin);
                                            //freopen("Abdimanabov","w",stdout);

                                            int n; cin>>n; set<char> st;
                                            rep(i,0,n)
                                            {
                                                string s; cin>>s;
                                                int now=0;
                                                for(auto x: s)
                                                {
                                                    int son;
                                                    if(x>='0'&&x<='9')
                                                        son=x-'0';
                                                    else
                                                        son=x-'A'+10;
                                                    rep(q,0,4)
                                                    {
                                                    a[i][now++]=ikk[son][q];
                                                    st.insert(ikk[son][q]);
                                                    }
                                                }
                                            }
                                            int ans=-1;
                                            rep(i,0,n)
                                            {
                                                int now=0;
                                                while(now<n)
                                                {
                                                    int sana=1;
                                                    now++;
                                                    while(now<n&&a[i][now]==a[i][now-1])sana++,now++;
                                                        if(ans==-1)ans=sana;
                                                    else ans=__gcd(ans,sana);
                                                }
                                            }
                                            rep(i,0,n)
                                            {
                                                int now=0;
                                                while(now<n)
                                                {
                                                    int sana=1;
                                                    now++;
                                                    while(now<n&&a[i][now]==a[i][now-1])sana++,now++;
                                                        ans=__gcd(ans,sana);
                                                }
                                            }

                                            cout<<ans;

                                        rt 0;

                                        }











