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 time
import bisect
import functools
import math
import os
import random
import re
import sys
import threading
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import cmp_to_key, lru_cache, reduce
from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest
from io import BytesIO, IOBase
from itertools import accumulate, combinations, permutations
from operator import add, iand, ior, itemgetter, mul, xor
from string import ascii_lowercase, ascii_uppercase
from typing import *

from types import GeneratorType

def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc

BUFSIZE = 4096
inf = float('inf')
if "PyPy" in sys.version:
    import pypyjit; pypyjit.set_param('max_unroll_recursion=-1')

RANDOM = random.getrandbits(32)

class Wrapper(int):
    def __init__(self, x):
        int.__init__(x)

    def __hash__(self):
        return super(Wrapper, self).__hash__() ^ RANDOM

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin = IOWrapper(sys.stdin)
sys.stdout = IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def I():
    return input()

def II():
    return int(input())

def MII():
    return map(int, input().split())

def LI():
    return list(input().split())

def LII():
    return list(map(int, input().split()))

def GMI():
    return map(lambda x: int(x) - 1, input().split())

def LGMI():
    return list(map(lambda x: int(x) - 1, input().split()))

class Trie_01:

    __slots__ = ['depth', 'zero', 'one', 'zero_cnt', 'one_cnt']
    def __init__(self, n):
        self.depth = n
        self.zero = None
        self.one = None
        self.zero_cnt = 0
        self.one_cnt = 0

    def insert(self, num):
        tmp = self.depth
        node = self
        while tmp:
            tmp -= 1
            if num & (1 << tmp):
                if not node.one:
                    node.one = Trie_01(tmp)
                node.one_cnt += 1
                node = node.one
            else:
                if not node.zero:
                    node.zero = Trie_01(tmp)
                node.zero_cnt += 1
                node = node.zero

    def delete(self, num):
        tmp = self.depth
        node = self
        while tmp:
            tmp -= 1
            if num & (1 << tmp):
                node.one_cnt -= 1
                node = node.one
            else:
                node.zero_cnt -= 1
                node = node.zero

    def findMaxXor(self, num):
        tmp = self.depth
        node = self
        ans = 0
        while tmp:
            tmp -= 1
            if num & (1 << tmp):
                if node.zero_cnt:
                    node = node.zero
                    ans += 1 << tmp
                else:
                    node = node.one
            else:
                if node.one_cnt:
                    node = node.one
                    ans += 1 << tmp
                else:
                    node = node.zero
        return ans

    def findMinXor(self, num):
        tmp = self.depth
        node = self
        ans = 0
        while tmp:
            tmp -= 1
            if num & (1 << tmp):
                if node.one_cnt:
                    node = node.one
                else:
                    node = node.zero
                    ans += 1 << tmp
            else:
                if node.zero_cnt:
                    node = node.zero
                else:
                    node = node.one
                    ans += 1 << tmp
        return ans

    def countXorRange(self, low, high, num):
        if self.depth == 1:
            ans = 0
            if low <= 1 ^ num <= high: ans += self.one_cnt
            if low <= num <= high: ans += self.zero_cnt
            return ans
        val = 1 << (self.depth - 1)
        if low == 0 and high == 2 * val - 1: return self.one_cnt + self.zero_cnt
        if low & val != high & val:
            return self.countXorRange(low, val-1, num) + self.countXorRange(val, high, num)
        if low & val:
            if num & val:
                if self.zero_cnt == 0: return 0
                return self.zero.countXorRange(low - val, high - val, num - val)
            else:
                if self.one_cnt == 0: return 0
                return self.one.countXorRange(low - val, high - val, num)
        else:
            if num & val:
                if self.one_cnt == 0: return 0
                return self.one.countXorRange(low, high, num - val)
            else:
                if self.zero_cnt == 0: return 0
                return self.zero.countXorRange(low, high, num)


def getRes(nums, bit):
    if bit < 0: return len(nums) - 1
    nums1, nums2 = [], []
    note = 1 << bit
    for num in nums:
        if num >= note: nums1.append(num - note)
        else: nums2.append(num)

    if len(nums1) > len(nums2): nums1, nums2 = nums2, nums1
    if len(nums1) == 0: return getRes(nums2, bit-1)
    trie = Trie_01(bit + 1)
    for num in nums1:
        trie.insert(num)
    ans = inf
    for num in nums2:
        ans = min(ans, trie.findMinXor(num))
    return getRes(nums1, bit-1) + getRes(nums2, bit-1) + ans + note

n = II()
nums = LII()
print(getRes(nums, 29))