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, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def f(l, u, v):
    return (l << 40) ^ (u << 20) ^ v

def insert(x, c, la):
    j = 0
    for i in p:
        if x & i:
            if not G[j] >> 25:
                la += 1
                G[j] ^= la << 25
                j = la
            else:
                j = G[j] >> 25
        else:
            if not G[j] & 33554431:
                la += 1
                G[j] ^= la
                j = la
            else:
                j = G[j] & 33554431
        color[j] = c
    return la

def xor_min(x, c):
    j, ans = 0, 0
    for i in p:
        if not x & i:
            if color[G[j] >> 25] == c:
                j = G[j] >> 25
            else:
                ans += i
                j = G[j] & 33554431
        else:
            if color[G[j] & 33554431] == c:
                j = G[j] & 33554431
            else:
                ans += i
                j = G[j] >> 25
    return ans

n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
pow2 = [1]
l = 30
for _ in range(l):
    pow2.append(2 * pow2[-1])
p = pow2[::-1]
n = len(a)
st = [f(l, 0, n)]
ans = 0
G, color, c, la = [0] * 6000000, [0] * 6000000, 0, 0
while st:
    x = st.pop()
    l0, u, v = x >> 40, (x >> 20) & 1048575, x & 1048575
    c += 1
    if u == v or l0 < 0:
        continue
    p2 = pow2[l0]
    if p2 & a[u] == p2 & a[v - 1]:
        st.append(f(l0 - 1, u, v))
        continue
    m = u
    while not a[m] & p2:
        m += 1
    x, y = [u, m], [m, v]
    if m - u > v - m:
        x, y = y, x
    ans0 = pow2[l0 + 1]
    if (m - u) * (v - m) < 500:
        for i in range(x[0], x[1]):
            ai = a[i]
            for j in range(y[0], y[1]):
                ans0 = min(ans0, ai ^ a[j])
    else:
        for i in range(x[0], x[1]):
            la = insert(a[i], c, la)
        for i in range(y[0], y[1]):
            ans0 = min(ans0, xor_min(a[i], c))
    ans += ans0
    st.append(f(l0 - 1, u, m))
    st.append(f(l0 - 1, m, v))
print(ans)