#n,k = [int(x) for x in raw_input().split(' ')]
n = int(raw_input())

def nod(a,b):
    while a!=0 and b!=0:
        if a > b:
            a = a % b
        else:
            b = b % a
    return(a+b)

dels = list()
for i in range(n,0,-1):
    if n % i == 0:
        dels.append(i)

rows = list
prev = raw_input()
m = n
cur = 1
for _ in range(n-1):
    st = raw_input()
    row = list(bin(int(st,16)))[2:]
    if st == prev:
        cur += 1
    else:
        m = nod(m,cur)
        cur = 1
        prev = st
        if m == 1:
            break
    resrow = ['0'] * (n - len(row)) + row
    rowcur = 1
    for i in range(1,len(resrow)):
        if resrow[i] == resrow[i-1]:
            rowcur += 1
        else:
            m = nod(m,rowcur)
            rowcur = 1
            if m == 1:
                break
print(m)