n = int(input())
a = []
for i in range(n):
        s = input()
        tmp = []
        for j in range(n//4):
                c = format(int(s[j],16),"b")
                c = c.zfill(4)
                for k in c:
                        tmp.append(int(k))
        a.append(tmp)
ans = 1
import math
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n //= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
#a = factorization(n)
#b = []
#for i,j in a:
#  b.append(i)
def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    if n == 1:
      return([1])
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)
kk = divisor(n)
kk = kk[::-1]
print(a)
for i in kk:
        flag = 1
        for j in range(n//i):
                for k in range(n//i):
                    c = 0
                    for l in range(i):
                            for ll in range(i):
                                    c += a[j*i+l][k*i+ll]
                    if c == 0 or c == i*i:
                            continue
                    else:
                            flag = 0 
                if flag == 0:
                        break       
        else:
                print(ans*i)
                exit()