/*
Arrows wave the past behind.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int mp[5205][5205];
char s[5205][5];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a;
		scanf("%s",s[i]);
		int ss=strlen(s[i]);
		for(int j=0;j<ss;j++)
		{
			if(s[i][j]>='0'&&s[i][j]<='9')
				a=s[i][j]-'0';
			else
				a=s[i][j]-'A'+10;
			for(int k=1;k<=4;k++)
			{
				mp[i+1][j*4+5-k]=a%2;
				a/=2;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n&&ans!=1;i++)
	{
		for(int j=2,k=1;j<=n&&ans!=1;j++)
		{
			if(mp[i][j]!=mp[i][j-1])
			{
				ans=__gcd(ans,k);
				k=1;
			}
			else
				k++;
		}
		for(int j=2,k=1;j<=n&&ans!=1;j++)
		{
			if(mp[j][i]!=mp[j-1][i])
			{
				ans=__gcd(ans,k);
				k=1;
			}
			else
				k++;
		}
	}
	cout<<ans<<endl;
	return 0;
}