import sys
range = xrange
input = raw_input

def gcd(a,b):
    if b==0:return a
    while a>0:
        a,b = b%a,a
    return b

hex2bin = ['']*256
hex2bin[ord('0')] = '0000'
hex2bin[ord('1')] = '0001'
hex2bin[ord('2')] = '0010'
hex2bin[ord('3')] = '0011'
hex2bin[ord('4')] = '0100'
hex2bin[ord('5')] = '0101'
hex2bin[ord('6')] = '0110'
hex2bin[ord('7')] = '0111'
hex2bin[ord('8')] = '1000'
hex2bin[ord('9')] = '1001'
hex2bin[ord('A')] = '1010'
hex2bin[ord('B')] = '1011'
hex2bin[ord('C')] = '1100'
hex2bin[ord('D')] = '1101'
hex2bin[ord('E')] = '1110'
hex2bin[ord('F')] = '1111'


n = int(input())

x = 0
new_gcd = [True]*(n+1)
new_gcd[0] = False

prev = ''
count = 0
for line in sys.stdin.read().splitlines():
    if line==prev:
        count += 1
    else:
        if new_gcd[count]:
            x = gcd(count,x)
            new_gcd = [True]*(n+1)
            j = 0
            while j<=n:
                new_gcd[j]=False
                j+=x    
        count = 1
        prev = line

        prev_c = ''
        counter = 0
        for hexx in prev:
            for c in hex2bin[ord(hexx)]:
                if c==prev_c:
                    counter += 1
                else:
                    if new_gcd[counter]:
                        x = gcd(counter,x)
                        new_gcd = [True]*(n+1)
                        j = 0
                        while j<=n:
                            new_gcd[j]=False
                            j+=x    
                    counter = 1
                    prev_c = c
        
        if new_gcd[counter]:
            x = gcd(counter,x)
            new_gcd = [True]*(n+1)
            j = 0
            while j<=n:
                new_gcd[j]=False
                j+=x    
    if x==1:
        print 1
        sys.exit()

x = gcd(count,x)

print x
