def bn(x):
    d=int(x,16)
    return bin(d)


def matrix(n,a):
    for i in a:
        i=list(bn(i))
        i.pop(0)
        i.pop(0)
    return a


def funct(n,q):
    a=matrix(n,q)
    x=n
    while x!=1:
        x-=1
        flag=True
        if(n//x==0):
            for i in range(len(a)):
                for j in range(len(a)):
                    if(i//x==0 and j//x==0):
                        if a[i][j]!=a[i//x][j//x]:
                            flag==False
                            break
            if flag==True:
                print(x)
                break
    if x==1:
        print('1')
    if flag==False:
        print('-1')


n=int(input())
d=[]
for i in range(n):
    x=input()
    d.append(x)
funct(n,d)
