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
V = 2
MX = 3;
class Node:
    def __init__(self) -> None:
        self.childs = [None]*V
        self.ended = False
        self.val = -1
        self.cnt = 0
root = Node()
def add(x):
    cur = root
    for i in range(MX,-1,-1): # store from msb...lsb
        ind = (x>>i)&1
        if not cur.childs[ind]: cur.childs[ind] = Node()
        cur = cur.childs[ind]
    cur.ended = 1;
    cur.cnt+=1
    cur.val = x
def reset():
    global root
    root = Node()
def remove(x):
    cur = root
    path = []
    for i in range(MX,-1,-1): # store from msb...lsb
        ind = (x>>i)&1
        path.append((cur,ind))
        cur = cur.childs[ind]
    cur.cnt -=1
    if cur.cnt==0:
        while path:
            p,i = path.pop()
            p.childs[i] = None
            if p.childs[i^1]: break 
"""
Find max xor of x in trie
"""
def min_xor(x):
    cur = root
    for i in range(MX,-1,-1):
        if not cur: return float('inf')
        ind = (x>>i)&1
        if cur.childs[ind]: cur = cur.childs[ind]
        else: cur = cur.childs[ind^1]
    return cur.val^x

n = int(input())
A = list(map(int,input().split()))
A.sort() # order doesnt matter
ans = 0
def dnq(l,r,b): # 
    global ans
    if l>=r: return 
    reset()
    m = l
    while m<=r and (A[m]&(1<<b))==0: 
        add(A[m])
        m +=1
    if m==l or m>r: 
        dnq(l,r,b-1)
        return 
    xr = float('inf')
    for j in range(m,r+1):
        xr = min(xr,min_xor(A[j]))
    ans += xr if xr<float('inf') else 0
    dnq(l,m-1,b-1)
    dnq(m,r,b-1)

dnq(0,n-1,29)
print(ans)
    