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
import sys
input = sys.stdin.buffer.readline 
 
def f(T, k):
    if k==0:
        return 0
    if T[0] is None and T[1] is None:
        return 0
    elif T[1] is None:
        return f(T[0], k-1)
    elif T[0] is None:
        return f(T[1], k-1)
    else:    
        a1 = f(T[0], k-1)
        a2 = f(T[1], k-1)
        return a1+a2+g(T[0], T[1], k-1)+2**(k-1)
    
def g(T1, T2, k):
    if k==0:
        return 0
    A, B = T1
    C, D = T2
    answer = float('inf')
    if A is None and D is None:
        return 2**(k-1)+g(B, C, k-1)
    elif B is None and C is None:
        return 2**(k-1)+g(A, D, k-1)
    else:
        if A is not None and C is not None:
            a1 = g(A, C, k-1)
            answer = min(answer, a1)
        if B is not None and D is not None:
            a2 = g(B, D, k-1)
            answer = min(answer, a2)
        return answer
 
def process(A):
    n = len(A)
    trie = [None, None]
    for i in range(n):
        ai = A[i]
        bi = bin(ai)[2:].zfill(30)
        start = trie
        for j in range(30):
            d = int(bi[j])
            if start[d] is None:
                start[d] = [None, None]
            start = start[d]
    print(f(trie, 30))
    
n = int(input())
A = [int(x) for x in input().split()]
process(A)