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.exist = 0
        self.parent = None

class BitTrie:
    def __init__(self, data):
        self.root = Node()
        for val in data:
            current = self.root
            binary = bin(val)[2:]
            binary =['0'] * (30 - len(binary)) + list(binary)
            for bit in binary:
                prev = current
                if bit =='0':
                    if current.left == None:
                        current.left = Node()
                        
                    current = current.left
                else:
                    if current.right == None:
                        current.right = Node()
                    current = current.right
                current.parent = prev
                    
            current.exist += 1
        
    def find_min(self, val):
        binary = bin(val)[2:]
        binary = ['0'] * (30 - len(binary)) + list(binary)
        
        cost = 0
        current = self.root
        value = 0
        for i in range(30):
            if binary[i] == '0':
                if current.left != None:
                    current = current.left
                else:
                    cost += 1 << (29 - i)
                    current = current.right
                    value += 1 << (29 - i)
            else:
                if current.right != None:
                    current = current.right
                    value += 1 << (29 - i)
                else:
                    current = current.left
                    cost += 1 << (29 - i)
                    
        return (cost, value, val)
    
    def remove(self, val):
        binary = bin(val)[2:]
        binary = ['0'] * (30 - len(binary)) + list(binary)
        current = self.root
        for i in range(30):
            if binary[i] == '0':
                current = current.left
            else:
                current = current.right
        
        current.exist -= 1
        
        if current.exist == 0:
            
            
            while 1:
                parent = current.parent
                if parent == None:
                   
                    break
                if parent.left != None and parent.right!=None:
                    
                    if parent.left == current:
                        parent.left = None
                    else:
                        parent.right = None
                    break
                else:
                    
                    parent.left = None
                    parent.right = None
                
                current = parent
                

import heapq
# (cost, i, through j)
min_cost = []
heapq.heapify(min_cost)

n = int(input())
data = list(map(int, input().split()))
trie = BitTrie(data)
start_val = data[0]
trie.remove(data[0])

heapq.heappush(min_cost, trie.find_min(start_val))

answer = 0

count = {}
for x in data:
    if x not in count:
        count[x] = 1
    else:
        count[x] += 1
count[data[0]] -= 1

if count[data[0]] == 0:
    del count[data[0]]
    

i = 0
while i < n - 1:
    node = heapq.heappop(min_cost)
    if node[1] not in count:
        heapq.heappush(min_cost, trie.find_min(node[2]))
        continue
    i += 1
    count[node[1]] -= 1
    if count[node[1]] == 0:
        del count[node[1]]
    
    answer += node[0]
    if i == n - 1:
        break
    trie.remove(node[1])
    
    heapq.heappush(min_cost, trie.find_min(node[1]))
    heapq.heappush(min_cost, trie.find_min(node[2]))
    
print(answer)
    