def check(sol, n, mat):
    k = n/sol
    for i in range(k):
        for j in range(k):
            s = 0
            for h in range(sol):
                s += sum(mat[h+i*sol][j*sol:(j+1):sol])
            if s != 0 and s != sol * sol:
                return False
    return True

def divi(n):
    l = [2,4]
    k = n/4
    for i in range(2,k+1):
        if k%i == 0:
            l += [4*i]
    return l[::-1]
    
def f(n,mat):
    div = divi(n)
    for sol in div:
        if check(sol, n, mat):
            return sol
    return 1

if __name__ == '__main__':
    n = int(input())
    d = {'0': [0,0,0,0],
        '1': [0,0,0,1],
        '2': [0,0,1,0],
        '3': [0,0,1,1],
        '4': [0,1,0,0],
        '5': [0,1,0,1],
        '6': [0,1,1,0],
        '7': [0,1,1,1],
        '8': [1,0,0,0],
        '9': [1,0,0,1],
        'A': [1,0,1,0],
        'B': [1,0,1,1],
        'C': [1,1,0,0],
        'D': [1,1,0,1],
        'E': [1,1,1,0],
        'F': [1,1,1,1]}
    mat = [[0]*n]*n
    for i in range(n):
        s = str(raw_input())
        a = [0] * n
        for j in range(n/4):
            a[4*j:4*(j+1)] = d[s[j]]
        mat[i] = a
    print f(n,mat)