/*
Solved by sid2104
on 10/06/2020  19:05 
*/
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define float       long double
#define pb          push_back
#define ld          long double
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vpii         vector<pair<int,int> >
#define mii         map<int,int>
#define all(a)      (a).begin(),(a).end()
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();
//#define debug(x)    ;
#define mp          make_pair
#define x           first
#define y           second
#define pb          push_back
#define endl        '\n'
#define si(x)       (int)((x).size())
#define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define txt         freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
#define tree        vector<vector<int> >
#define PI          3.14159265358979323846
int inf=99999999999;
const int mod=1e9+7;
const int cmp=1e17;
void inp(int n,int arr[])
{
    f(i,0,n) cin>>arr[i];
}
tree v(20);
void binary(int a)
{
    int k=a;
    vector<int> vv;
  f(i,0,4)
  {
      vv.pb(a%2);
      a/=2;
  }
  reverse(all(vv));
  v[k]=vv;
}
void solve()
{
    int n;
    cin>>n;
    f(i,0,16)
    binary(i);
    int a[n][n];
    f(i,0,n)
    {
        f(j,0,n/4)
        {
            char c;
            cin>>c;
            int p;
            if(c>='A'&&c<='F')
            {
                p=c-'A'+10;
            }
            else p=c-'0';
           f(k,0,4)
           {
               a[i][j*4+k]=v[p][k];
           }
        }

    }
    vector<int> factors;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            factors.pb(i);
            if(i!=n/i) factors.pb(n/i);
        }
    }
    sort(factors.rbegin(),factors.rend());
   
    for(int el:factors)
    {
        int check=1;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                
                i++;
                j++;
                int ii=i/el+(i%el!=0);
                int jj=j/el+(j%el!=0);
                i--;
                j--;
                ii--;
                jj--;
                if(a[i][j]!=a[ii][jj])
                {
                  
                    check=0;
                    break;
                }
            }
            if(check==0)
            break;
        }
        if(check)
        {
            cout<<el<<endl;
            return;
        }
    }

}
main()
{
    IOS;
    
    solve();
  

}








