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
class Node:
    def __init__(self):
        self.left = None
        self.right = None
        self.data = []

n = int(input())
data = list(map(int, input().split()))
data = list(set(data))
root = Node()

for x in data:
    current = root
    
    for bit in reversed(range(30)):
        
        if (x>>bit) & 1:
            if current.right == None:
                current.right = Node()
            current = current.right
            
        else:
            if current.left == None:
                current.left = Node()
            current = current.left
            
        current.data.append(x)




stack = []
stack.append((root, 29))
total_cost = 0
while stack:
    current, bit = stack.pop()
    
    if current.left == None and current.right == None:
        continue
    if current.left == None:
        stack.append((current.right, bit - 1))
        continue
    if current.right == None:
        stack.append((current.left, bit - 1))
        continue
    
    stack.append((current.left, bit - 1))
    stack.append((current.right, bit - 1))
    
    if len(current.left.data) < len(current.right.data):
        to_search = current.left.data
        search_in = current.right
    else:
        to_search = current.right.data
        search_in = current.left
    total_cost += 1 << bit
    min_cost = 10**10
    for x in to_search:
        current = search_in
        current_cost = 0
        for i in reversed(range(bit)):    
            if (x >> i) & 1:
                if current.right != None:
                    current = current.right
                else:
                    current = current.left
                    current_cost += 1 << i
            else:
                if current.left != None:
                    current = current.left
                else:
                    current = current.right
                    current_cost += 1 << i
        
        min_cost = min(min_cost, current_cost)
    
    total_cost += min_cost
    
    
print(total_cost)