#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
string foo(int x)
{
	string s;
	while(x!=0)
	{
		s.pb(x%2+'0');
		x=x/2;
	}
	
	while(s.length()!=4)
	{
		s.pb('0');
	}
	reverse(all(s));
	return s;
	
}


int main()
{
	fast;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n,i,j;
		cin>>n;
		string s[n];
		char c;
		for(i=0;i<n;i++)
		{
			for(j=0;j<n/4;j++)
			{
				cin>>c;
				string s1;
				if(c>='0'&&c<='9')
				{
					s1=foo(c-'0');
				}
				else
				{
					s1=foo(c-'A'+10);
					
				}
				
				for(int k=0;k<4;k++)
				{
					s[i].pb(s1[k]);
				}
				
			}
		}
		
		int dp[n+1][n+1];
		mem(dp,0);
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
				if(s[i-1][j-1]=='1')
				{
					dp[i][j]++;
				
				}
			}
		}
		vector<int>v;
		for(i=1;i*i<=n;i++)
		{
			if(n&i==0)
			{
				v.pb(i);
				if(i!=n/i)
				v.pb(n/i);
			}
		}
		sort(all(v),greater<int>());
		for(int k=0;k<(int)v.size()-1;k++)
		{
			int f=0;
			for(i=1;i<=n;i=i+v[k])
			{
				if(f==1)
				break;
				
				for(j=1;j<=n;j=j+v[k])
				{
					int x=dp[i+v[k]-1][j+v[k]-1]-dp[i-1][j+v[k]-1]-dp[i+v[k]-1][j-1];
					x=x+dp[i-1][j-1];
					if(x==0||x==v[k]*v[k])
					{
						
					}
					else
					{
						f=1;
						break;
					}
					
				}
			}
			if(!f)
			{
				cout<<v[k];
				return 0;
			}
		}
		cout<<1;
		
		
	}
}