def calc(r1,r2,c1,c2):
    return dp[r2][c2]-dp[r2][c1]-dp[r1][c2]+dp[r1][c1]
from sys import stdin
raw_input = stdin.readline
l=[]
n=input()
for i in xrange(n):
    r=raw_input()
    x=bin(int(r,16))[2:]
    x=max(0,n-len(x))*'0'+x
    #print x
    l.append(map(int,x))
dp=[[0 for i in xrange(n+1)] for j in xrange(n+1)]
for i in xrange(n):
    for j in xrange(n):
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]-dp[i][j]+l[i][j]
for x in xrange(n,0,-1):
    if n%x==0:
        f=0
        #print 
        for i in xrange(0,n,x):
            for j in xrange(0,n,x):
                sm=calc(i,i+x,j,j+x)
                #print x,sm,f
                if f or (sm!=x*x and sm!=0):
                    f=1
                    break
            if f:
                break
        if not f:
            print x
            exit()
