import sys

def find_divisor(n):
    divisors = [1]
    for i in range(2, n):
        if n % i == 0:
            divisors.append(i)
    divisors.append(n)
    return divisors

def check_all_element_equal(matrix, top_left, m):
    sub_matrix = []
    top, left = top_left
    for row in matrix[top:top+m]:
        for value in row[left:left+m]:
            sub_matrix.append(int(value))

    # print sub_matrix
    total = sum(sub_matrix)
    if total / len(sub_matrix) == sub_matrix[0]:
        return True
    else:
        return False


n = int(sys.stdin.readline().strip())
# print n
matrix = []

for i in range(n):
    row = bin(int(sys.stdin.readline().strip(), 16))[2:].zfill(n)
    # row = map(lambda y: bin(y)[2:].zfill(n), map(lambda x: int(x, 16), sys.stdin.readline().strip()))
    matrix.append(row)

divisors = find_divisor(n)
# print matrix
for div in divisors[::-1]:
    if div == 1:
        sys.stdout.write("1\n")
        break

    compress_size = n / div
    m = n / compress_size
    check_list = []
    for i in range(compress_size):
        for j in range(compress_size):
            top, left = m * i, m * j
            if check_all_element_equal(matrix, top_left=(top, left), m=m):
                check_list.append(1)
            else:
                check_list.append(0)

    if sum(check_list) == len(check_list):
        sys.stdout.write("%d\n" % div)
        break
