from math import gcd
n = int(input())
a = [[2]*(n+1) for _ in range(n+1)]

for i in range(n):
    j = 0
    for x in map(lambda c: int(c, 16), input()):
        for d in range(3, -1, -1):
            a[i][j] = 1 if (1 << d) & x else 0
            j += 1
    a[i][-1] = 2

a[-1] = [2] * (n+1)

ans = 0
for i in range(n):
    prev, cont = a[i][0], 1
    for j in range(1, n+1):
        if prev != a[i][j]:
            if ans == 0:
                ans = cont
            else:
                ans = gcd(ans, cont)
            prev, cont = a[i][j], 1
        else:
            cont += 1

for j in range(n):
    prev, cont = a[0][j], 1
    for i in range(1, n+1):
        if prev != a[i][j]:
            ans = gcd(ans, cont)
            prev, cont = a[i][j], 1
        else:
            cont += 1

print(ans)
