from sys import stdin
from copy import deepcopy


def factorize(n):  # o(sqr(n))
    c, ans = 1, []
    while (c * c < n):
        if n % c == 0:
            ans.extend([c, n // c])
        c += 1

    if c * c == n:
        ans.append(c)
    return sorted(ans)[1:]


rstr = lambda: stdin.readline().strip()
n = int(input())
form, ans = '{:0>' + str(n) + 'b}', 1
mat = [form.format(int(rstr(), 16)) for _ in range(n)]
fac = factorize(n)

for f in fac:
    mat1 = [[] for _ in range(n // f)]
    for r in range(0, len(mat), f):
        for c in range(0, len(mat), f):
            dis = set()
            for i in range(r, r + f):
                for j in range(c, c + f):
                    dis.add(mat[i][j])

            if len(dis) == 2:
                print(ans)
                exit()
            mat1[r // f].append(dis.pop())

    ans += 1
    mat = deepcopy(mat1)

print(ans)
