You are given a complete undirected graph with *n* vertices. A number *a*<sub class="lower-index">*i*</sub> is assigned to each vertex, and the weight of an edge between vertices *i* and *j* is equal to *a*<sub class="lower-index">*i*</sub> *xor* *a*<sub class="lower-index">*j*</sub>.

Calculate the weight of the minimum spanning tree in this graph.
The first line contains *n* (1 ≤ *n* ≤ 200000) — the number of vertices in the graph.

The second line contains *n* integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (0 ≤ *a*<sub class="lower-index">*i*</sub> &lt; 2<sup class="upper-index">30</sup>) — the numbers assigned to the vertices.
none
5
1 2 3 4 5
8
4
1 2 3 4
8
1
1
0
# Input
# The first line contains n  — the number of vertices in the graph.
#
# The second line contains n integers a1, a2, ..., an — the numbers assigned to the vertices.
#
# Output
# Print one number — the weight of the minimum spanning tree in the graph.

# 5
# 1 2 3 5 4
def XOR(a, b):
    return a ^ b


def make_adj_list(vertices: list):
    adj_list = {}
    for i in vertices:
        adj_list[i] = {x: XOR(x, i) for x in vertices if x != i}
    return adj_list


def getMinVertex(mstSet: dict, distance: dict):
    minimum = int(inf + 2)
    min_vertex = 0
    for V in vertices:
        if (mstSet[V] == 0) and (distance[V] < minimum):
            minimum = distance[V]
            min_vertex = V
    return min_vertex, minimum



def MST(adj_list: dict):
    primDistance = {i: inf for i in vertices}
    MSTSet = {i: 0 for i in vertices}
    parent = {i: " " for i in vertices}


    weight_sum = 0
    curr_parent = -1
    primDistance[vertices[0]] = 0

    for i in range(number_of_el - 1):
        U, distance = getMinVertex(MSTSet, primDistance)
        weight_sum += distance
        # print(distance)


        if U == 0:
            return weight_sum

        parent[U] = curr_parent
        curr_parent = U
        MSTSet[U] = 1


        for V in vertices:
            #relaxation
            if (V != U):
                primDistance[V] = min(primDistance[V], adj_list[U][V])
                # try:
                #     primDistance[V] = min(primDistance[V], adj_list[U][V])
                # except:
                #     continue

    U, distance = getMinVertex(MSTSet, primDistance)
    weight_sum += distance
    return weight_sum




inf = int('0b1111111111111111111111111111111', 2)

number_of_el = int(input())
vertices_str = str(input())
vertices = vertices_str.split(" ")
vertices = [int(x) for x in vertices]

adj_list_ = make_adj_list(vertices)
print(MST(adj_list_))




