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
def calc(a,k):
  if len(a)<=1:
    return 0
  if k<0:
    return 0
  c0=[]
  c1=[]
  for i in a:
    if (i>>k)&1:
      c1.append(i^(1<<k))
    else:
      c0.append(i)
  res=1<<30
  if len(c0)>=2:
    res=min(res,calc(c0,k-1))
  if len(c1)>=2:
    res=min(res,calc(c1,k-1))
  if len(c0)==len(c1)==1:
    res=min(res,(1<<k)^c0[0]^c1[0])
  
  return res

def solve(a,k):
  if len(a)==0 or k<0:
    return 0
  c0=[]
  c1=[]
  for i in a:
    if (i>>k)&1:
      c1.append(i^(1<<k))
    else:
      c0.append(i)
  res=solve(c0,k-1)+solve(c1,k-1)
  if c0 and c1:
    res+=(1<<k)+calc(c0+c1,k-1)
  return res

n=int(input())
a=list(map(int,input().split()))
print(solve(a,30))