#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
	cin.tie(0),ios::sync_with_stdio(0);
	int n,ans=n,c=1,cur;
	cin>>n;
	vector<vector<bool>> arr(n,vector<bool>(n));
	string p,s;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(i)
		{
			if(s==p)
				c++;
			else
				ans=__gcd(ans,c),p=s,c=1;
		}
		else
			p=s;
		for(int j=0;j<n;j++)
		{
			if((j&3)==0)
				cur=(isdigit(s[j>>2])?s[j>>2]-'0':s[j>>2]-'A'+10);
			arr[j][i]=cur&(1<<(3-(j&3)));
		}
	}
	ans=__gcd(ans,c);
	c=1;
	for(int i=1;i<n;i++)
	{
		if(arr[i]==arr[i-1])
			c++;
		else
			ans=__gcd(ans,c),c=1;
	}
	ans=__gcd(ans,c);
	cout<<ans<<'\n';
	return 0;
}
