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


def fast2():
    import os, sys, atexit
    from cStringIO import StringIO as BytesIO
    # range = xrange
    sys.stdout = BytesIO()
    atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
    return BytesIO(os.read(0, os.fstat(0).st_size)).readline


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

n = int(input())
big, ans = 1 << n, n
mat = [bin(big | int(rstr(), 16))[3:] 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 = 0

for i in range(1, n):
    if get_col(mat, i) != get_col(mat, i - 1):
        all.append(cur)
        cur = 0
    cur += 1
    
all.append(cur)
print(reduce(gcd, all))
