from sys import stdin
from fractions import gcd
from functools import reduce

get_col = lambda arr, i: [row[i] for row in arr]
rstr = lambda: stdin.readline().strip()

n = int(input())
form = '{:0>' + str(n) + 'b}'
mat = [form.format(int(rstr(), 16)) for _ in range(n)]
all, cur = [], 1

for i in range(1, n):
    if mat[i] != mat[i - 1]:
        all.append(cur)
        cur = 0
    cur += 1

all.append(cur)
cur = 1

for i in range(1, n):
    for j in range(n):
        if mat[j][i] != mat[j][i - 1]:
            all.append(cur)
            cur = 0
            break
    cur += 1

all.append(cur)
# print(mat, all)
print(reduce(gcd, all))
