from __future__ import print_function,division
import sys
if sys.version_info < (3, 0):
    range = xrange

n = int(input())

A = [[0]*(n+1) for _ in range(n+1)]

B = {
    '0': (0,0,0,0),
    '1': (0,0,0,1),
    '2': (0,0,1,0),
    '3': (0,0,1,1),
    '4': (0,1,0,0),
    '5': (0,1,0,1),
    '6': (0,1,1,0),
    '7': (0,1,1,1),
    '8': (1,0,0,0),
    '9': (1,0,0,1),
    'A': (1,0,1,0),
    'B': (1,0,1,1),
    'C': (1,1,0,0),
    'D': (1,1,0,1),
    'E': (1,1,1,0),
    'F': (1,1,1,1),
}

s = sys.stdin.read().splitlines()
for i,line in enumerate(s):
    j = 0
    for c in line:
        for b in B[c]:
            A[i+1][j+1] = b + A[i][j+1] + A[i+1][j] - A[i][j]
            j += 1

def S(u,l,d,r):
    return A[d][r] - A[d][l] - A[u][r] + A[u][l]

for s in reversed(range(1,n+1)):
    if n%s == 0:
        sq = s**2
        for i in range(0,n,s):
            for j in range(0,n,s):
                if S(i,j,i+s,j+s) not in (0,sq):
                    break
            else:
                continue
            break
        else:
            print(s)
            break
