n=int(input())
lim=int(n**0.5)
a=[1]
for i in range(2,lim+1):
    if n%i==0:
        a.append(i)
l=len(a)
for i in range(l-1,-1,-1):
    a.append(n//a[i])
a.append(n)
trans={'0': '0000', '1': '0001', '2': '0010', '3': '0011', '4': '0100', '5': '0101',
       '6': '0110', '7': '0111', '8': '1000', '9': '1001',
       'A': '1010', 'B': '1011', 'C': '1100', 'D': '1101', 'E': '1110',
       'F': '1111'}
graph=[''.join([trans[i]for i in input()])for k in range(n)]
def tellpure(i,j,l):
    global graph
    if graph[i][j:j+l]=='1'*i:
        color=1
    elif graph[i][j:j+l]=='0'*i:
        color=0
    else:
        return False
    for k in range(i+1,i+l):
        if graph[k][j:j+l]!=['0'*i,'1'*i][color]:
            return False
    return True
        
def divcubic(l):
    global n
    for k in range(0,n,l):
        for j in range(0,n,l):
            if not tellpure(k,j,l):
                return False
    return True
i=1
l=len(a)
while i<l:
    if not divcubic(a[i]):
        k=i+1
        while k<l:
            if a[k]%a[i]==0:
               del a[k]
               l-=1
            else:
                k+=1
        del a[i]
        l-=1
    else:
        i+=1
print(a[-1])
       
        
            

    
