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
from collections import deque
import sys
input = sys.stdin.buffer.readline

def binary_trie(l):
    G0, G1, cnt = [-1], [-1], [0]
    return G0, G1, cnt, l

def insert(x):
    j = 0
    for i in range(l, -1, -1):
        cnt[j] += 1
        if x & pow2[i]:
            if G1[j] == -1:
                G0.append(-1)
                G1.append(-1)
                cnt.append(0)
                G1[j] = len(cnt) - 1
            j = G1[j]
        else:
            if G0[j] == -1:
                G0.append(-1)
                G1.append(-1)
                cnt.append(0)
                G0[j] = len(cnt) - 1
            j = G0[j]
    cnt[j] += 1
    return

def erase(x):
    j = 0
    for i in range(l, -1, -1):
        cnt[j] -= 1
        if x & pow2[i]:
            j = G1[j]
        else:
            j = G0[j]
    cnt[j] -= 1
    return

def xor_min(x):
    j = 0
    ans = 0
    for i in range(l, -1, -1):
        if not x & pow2[i]:
            if not G0[j] == -1 and cnt[G0[j]]:
                j = G0[j]
            else:
                ans += pow2[i]
                j = G1[j]
        else:
            if not G1[j] == -1 and cnt[G1[j]]:
                j = G1[j]
            else:
                ans += pow2[i]
                j = G0[j]
    return ans

n = int(input())
a = list(map(int, input().split()))
s = set(a)
a = list(s)
a.sort()
pow2 = [1]
for _ in range(30):
    pow2.append(2 * pow2[-1])
G0, G1, cnt, l = binary_trie(30)
n = len(s)
q = deque()
q.append((0, n - 1, l))
ans = 0
while q:
    u, v, l0 = q.popleft()
    if u == v or l0 < 0:
        continue
    p2 = pow2[l0]
    if p2 & a[u] == p2 & a[v]:
        q.append((u, v, l0 - 1))
        continue
    m = u
    while not a[m] & p2:
        insert(a[m])
        m += 1
    ans0 = pow2[l]
    for i in range(m, v + 1):
        ans0 = min(ans0, xor_min(a[i]))
    for i in range(u, m):
        erase(a[i])
    ans += ans0
    q.append((u, m - 1, l0 - 1))
    q.append((m, v, l0 - 1))
print(ans)