import random
from math import *

'''stdin=open('input.txt')

def input():
	return stdin.readline()[:-1]

stdout=open('output.txt',mode='w+')
def print(x,end='\n'):
	stdout.write(str(x)+end)
'''

# CODE BEGINS HERE.................

dic ={'0':[False,False,False,False],'1':[False,False,False,True],'2':[False,False,True,False],'3':[False,False,True,True],'4':[False,True,False,False],'5':[False,True,False,True],'6':[False,True,True,False],'7':[False,True,True,True],'8':[True,False,False,False],'9':[True,False,False,True],'A':[True,False,True,False],'B':[True,False,True,True],'C':[True,True,False,False],'D':[True,True,False,True],'E':[True,True,True,False],'F':[True,True,True,True]}
n=int(input())
l=[]
for i in range(n):
	s=input()
	temp=[]
	for j in s:
		temp+=dic[j]
	l.append(temp)
flag=True
for x in range(n):
	x=n-x
	if x%n:
		continue
	comp=[]
	for i in range(n//x):
		comp.append(['0']*(n//x))
	#print(comp)
	for i in range(n):
		for j in range(n):
			a=i//x
			b=j//x
			#print(i,j,a,b)
			#print(l)
			if(comp[a][b]=='0'):
				comp[a][b]=l[i][j]
			else:
				if comp[a][b] != l[i][j]:
					flag=False
					break
		if not flag:
			break
	if(flag):
		print(x)
		break
		
if not flag:
	print(1)

#CODE ENDS HERE....................

#stdout.close()

