Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.

As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.


-----Input-----

The first line contains integer $n$ ($1\le n \le 10^5$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).


-----Output-----

Print one integer — the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.


-----Examples-----
Input
3
1 2 3

Output
2

Input
2
1 5

Output
4



-----Note-----

In the first sample, we can choose $X = 3$.

In the second sample, we can choose $X = 5$.

Difficulty: HARD

Solutions:
import sys
input = sys.stdin.readline
n = int(input())
l = [int(i) for i in input().split()]
ans = 0

def xorchecker(l, ans, pow_):
	if pow_ == -1:
		return ans
	one = []
	zero = []
	for i in l:
		if i & 1 << pow_ != 0:
			one.append(i)
		else:
			zero.append(i)
	if zero == [] or one == []:
		return xorchecker(l, ans, pow_ - 1)
	else:
		return min(xorchecker(zero, ans + (1 << pow_), pow_ - 1), xorchecker(one, ans + (1 << pow_), pow_ - 1))
print(xorchecker(l, ans, 30))


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()

def rec(li, k):
	if not li or k < 0:
		return 0
	(li1, li2) = ([], [])
	for a in li:
		if a & 1 << k:
			li1.append(a)
		else:
			li2.append(a)
	if not li1 or not li2:
		return rec(li, k - 1)
	return min(rec(li1, k - 1), rec(li2, k - 1)) + (1 << k)
print(rec(A, 30))


import os, sys
from io import BytesIO, IOBase

class Node:

	def __init__(self):
		self.zero = None
		self.one = None
		self.onpath = 0

class Trie:

	def __init__(self, node):
		self.root = node

	def add(self, num):
		curr = self.root
		for bit in num:
			if bit == '1':
				if not curr.one:
					curr.one = Node()
				curr = curr.one
			else:
				if not curr.zero:
					curr.zero = Node()
				curr = curr.zero
			curr.onpath += 1

	def rec(self, curr, val):
		if not curr.zero and (not curr.one):
			return val
		if not curr.zero:
			return self.rec(curr.one, val << 1)
		if not curr.one:
			return self.rec(curr.zero, val << 1)
		return min(self.rec(curr.zero, val << 1 | 1), self.rec(curr.one, val << 1 | 1))

def main():
	n = int(input())
	a = list(map(lambda xx: bin(int(xx))[2:].zfill(30), input().split()))
	trie = Trie(Node())
	for i in a:
		trie.add(i)
	print(trie.rec(trie.root, 0))
BUFSIZE = 8192

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, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
seq = sorted(list(map(int, input().split())))
queue = [(0, n, 30, 0)]
best = 2 ** 30
while queue:
	(l, r, b, v) = queue.pop()
	if b >= 0:
		mask = 1 << b
		if not mask & seq[l] and mask & seq[r - 1]:
			for i in range(l, r):
				if mask & seq[i]:
					queue.append((l, i, b - 1, v + mask))
					queue.append((i, r, b - 1, v + mask))
					break
		else:
			queue.append((l, r, b - 1, v))
	else:
		best = min(best, v)
print(best)


import sys
input = sys.stdin.readline

def find(a, x, j, p):
	d = []
	e = []
	if j < 0:
		return x
	for i in range(len(a)):
		if a[i] & 1 << j:
			d.append(a[i])
		else:
			e.append(a[i])
	if len(e) == 0:
		x = find(d, x, j - 1, p)
	elif len(d) == 0:
		x = find(e, x, j - 1, p)
	else:
		x = min(find(e, x, j - 1, p), find(d, x, j - 1, p)) | 1 << j
	return x
n = int(input())
a = [int(x) for x in input().split()]
print(find(a, 0, len(bin(max(a))[2:]), a))


import sys
input = sys.stdin.readline
n = int(input())
A = tuple(map(int, input().split()))
ANS = 0

def calc(A, ANS, keta):
	if keta == -1:
		return ANS
	Z = []
	O = []
	for a in A:
		if a & 1 << keta != 0:
			Z.append(a)
		else:
			O.append(a)
	if Z == [] or O == []:
		return calc(A, ANS, keta - 1)
	else:
		return min(calc(Z, ANS + (1 << keta), keta - 1), calc(O, ANS + (1 << keta), keta - 1))
print(calc(A, 0, 30))


import bisect
import collections
input()
a = [int(_) for _ in input().strip().split()]
a.sort()
que = collections.deque()

def recur(su, a, cur, exp, lo, hi):
	global que
	if exp == -1:
		return
	newcur = cur + (1 << exp)
	ind = bisect.bisect_left(a, newcur, lo, hi)
	if ind != hi and ind != lo:
		que.append((su + (1 << exp), a, cur, exp - 1, lo, ind))
		que.append((su + (1 << exp), a, newcur, exp - 1, ind, hi))
	if ind == hi:
		que.append((su, a, cur, exp - 1, lo, hi))
	if ind == lo:
		que.append((su, a, newcur, exp - 1, lo, hi))
que.append((0, a, 0, 31, 0, len(a)))
si = len(que)
ma = 0
while si:
	ele = que.pop()
	ma = ele[0]
	que.append(ele)
	for q in que:
		ma = min(ma, q[0])
	while si:
		ele = que.popleft()
		if ele[0] == ma:
			recur(*ele)
		si -= 1
	si = len(que)
print(ma)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	if n == 1:
		print(0)
		exit()
	arr = list(map(int, input().split()))

	def solve(zz, z):
		if not zz or z == 0:
			return 0
		zero = []
		one = []
		for item in zz:
			if item & z:
				one.append(item)
			else:
				zero.append(item)
		if not zero:
			return solve(one, z >> 1)
		if not one:
			return solve(zero, z >> 1)
		return z + min(solve(zero, z >> 1), solve(one, z >> 1))
	print(solve(arr, 1 << 29))
BUFSIZE = 8192

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, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math

def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problem1():
	n = inp(int)
	s = inp()
	print(n + 1)

def problem2():
	t = inp(int)
	for _ in range(t):
		n = inp(int)
		a = inp(int, strip=False)
		s1 = sum(a)

		def search(b):
			(mx, cur) = (-10 ** 10, 0)
			for el in b:
				cur += el
				if cur > mx:
					mx = cur
				if cur < 0:
					cur = 0
			return mx
		s2 = max(search(a[:-1]), search(a[1:]))
		if s1 > s2:
			print('YES')
		else:
			print('NO')

def problem3():
	x_raw = inp(int)
	x = x_raw
	(p, k) = ([], [])
	for j in range(2, int(math.sqrt(x)) + 2):
		power = 0
		while x % j == 0:
			x = x // j
			power += 1
		if power > 0:
			p.append(j)
			k.append(power)
	if x > 1:
		p.append(x)
		k.append(1)

	def find(p, k, pos, tp):
		if pos == len(p):
			(x1, x2) = (1, 1)
			for i in range(len(p)):
				num = p[i] ** k[i]
				if tp[i]:
					x1 *= num
				else:
					x2 *= num
			return max(x1, x2)
		tp[pos] = 0
		res1 = find(p, k, pos + 1, tp)
		tp[pos] = 1
		res2 = find(p, k, pos + 1, tp)
		return min(res1, res2)
	tp = [0 for i in range(len(p))]
	res = find(p, k, 0, tp)
	print(res, x_raw // res)

def problem4():
	n = inp(int)
	a = inp(int, strip=False)
	a = sorted(a)
	a = [bin(el)[2:] for el in a]
	a = [[int(s) for s in el] for el in a]
	m = max([len(el) for el in a])
	a = [[0 for _ in range(m - len(el))] + el for el in a]
	res = [0 for _ in range(m)]

	def solve(p, r, pos):
		if pos == m:
			return 0
		n1 = sum([el[pos] for el in a[p:r + 1]])
		if n1 == 0:
			res[pos] = 0
			return solve(p, r, pos + 1)
		elif n1 == r - p + 1:
			res[pos] = 1
			return solve(p, r, pos + 1)
		else:
			q = r - n1
			k0 = solve(p, q, pos + 1)
			k1 = solve(q + 1, r, pos + 1)
			if k0 < k1:
				res[pos] = 1
				return 2 ** (m - pos - 1) + k0
			else:
				res[pos] = 0
				return 2 ** (m - pos - 1) + k1
	res = solve(0, len(a) - 1, 0)
	print(res)
problem4()


def abc(x, i, l):
	a = []
	b = []
	for j in l:
		if x[j][i] == '1':
			a.append(j)
		else:
			b.append(j)
	if i == 30:
		if a and b:
			return '1'
		return '0'
	if a and b:
		return '1' + min(abc(x, i + 1, a), abc(x, i + 1, b))
	if a:
		return '0' + abc(x, i + 1, a)
	return '0' + abc(x, i + 1, b)
n = int(input())
l = list(map(int, input().split()))
x = []
for i in l:
	d = '{0:031b}'.format(i)
	x.append(d)
d = abc(x, 0, [i for i in range(n)])
print(int(d, 2))


n = int(input())
aa = list(map(int, input().split()))

def help(a, bits):
	if len(a) <= 1 or bits < 0:
		return 0
	(s, u) = (list(), list())
	for i in a:
		if i >> bits & 1 == 0:
			u.append(i)
		else:
			s.append(i)
	if len(u) == 0:
		return help(s, bits - 1)
	elif len(s) == 0:
		return help(u, bits - 1)
	return min(help(u, bits - 1), help(s, bits - 1)) + (1 << bits)
print(help(aa, 30))


def func(arr, bitmask):
	if bitmask == 0:
		return 0
	arr_off = []
	arr_on = []
	for num in arr:
		if num & bitmask == 0:
			arr_off.append(num)
		else:
			arr_on.append(num)
	if not arr_off:
		return func(arr_on, bitmask >> 1)
	if not arr_on:
		return func(arr_off, bitmask >> 1)
	return bitmask + min(func(arr_on, bitmask >> 1), func(arr_off, bitmask >> 1))
n = int(input())
arr = map(int, input().split())
ans = func(arr, 1 << 29)
print(ans)


def q(s, b):
	if not s or b < 0:
		return 0
	(n, f) = ([], [])
	for i in s:
		if i & 1 << b:
			n += (i,)
		else:
			f += (i,)
	if not n:
		return q(f, b - 1)
	if not f:
		return q(n, b - 1)
	return min(q(n, b - 1), q(f, b - 1)) + 2 ** b
input()
print(q([*map(int, input().split())], 32))


DIG = 29

def build_xor_tree(a, n):
	tree = [[-1, -1]]
	for i in range(n):
		cur = 0
		for pos in range(DIG, -1, -1):
			if a[i] & 1 << pos:
				if tree[cur][1] == -1:
					tree.append([-1, -1])
					tree[cur][1] = len(tree) - 1
				cur = tree[cur][1]
			else:
				if tree[cur][0] == -1:
					tree.append([-1, -1])
					tree[cur][0] = len(tree) - 1
				cur = tree[cur][0]
	return tree

def possible(tree, cur, x, pos):
	if pos < 0:
		return True
	if cur == -1:
		return False
	if x & 1 << pos:
		return possible(tree, tree[cur][0], x, pos - 1) or possible(tree, tree[cur][1], x, pos - 1)
	if tree[cur][0] != -1 and tree[cur][1] != -1:
		return False
	if tree[cur][0] != -1:
		return possible(tree, tree[cur][0], x, pos - 1)
	return possible(tree, tree[cur][1], x, pos - 1)
n = int(input())
a = list(map(int, input().split()))
tree = build_xor_tree(a, n)
lo = 0
hi = (1 << DIG + 1) - 1
while lo < hi - 1:
	mid = (lo + hi) // 2
	if possible(tree, 0, mid, DIG):
		hi = mid
	else:
		lo = mid + 1
if possible(tree, 0, lo, DIG):
	print(lo)
else:
	print(hi)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def go(a, bit):
	if bit < 0:
		return 0
	set = []
	notset = []
	for i in range(len(a)):
		if 1 << bit & a[i] != 0:
			set.append(a[i])
		else:
			notset.append(a[i])
	if len(set) == 0:
		return go(notset, bit - 1)
	if len(notset) == 0:
		return go(set, bit - 1)
	return min(go(set, bit - 1), go(notset, bit - 1)) + (1 << bit)

def solve():
	t = 1
	for tt in range(t):
		n = nu()
		a = li()
		print(go(a, 30))
solve()


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left
mod = 998244353
mod = 1000000007

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b

def moduloinverse(a):
	return pow(a, mod - 2, mod)

def solve1(l, bit):
	if bit < 0:
		return 0
	a = []
	b = []
	for i in l:
		if i & 1 << bit:
			a.append(i)
		else:
			b.append(i)
	if a and b:
		return min(solve1(a, bit - 1), solve1(b, bit - 1)) + (1 << bit)
	if a:
		return solve1(a, bit - 1)
	if b:
		return solve1(b, bit - 1)

def solve(we):
	n = iin()
	l = lin()
	print(solve1(l, 30))
qwe = 1
for _ in range(qwe):
	solve(_ + 1)


import sys
X = int(sys.stdin.readline())
a = set([int(i) for i in sys.stdin.readline().split()])
top = 1 << 31
ans = 0

def best(s, cur):
	if len(s) == 0 or cur == 0:
		return 0
	hasCur = set()
	hasNotCur = set()
	for i in s:
		if i & cur == 0:
			hasNotCur.add(i)
		else:
			hasCur.add(i)
	if len(hasNotCur) == 0 or len(hasCur) == 0:
		return best(s, cur >> 1)
	else:
		return cur + min(best(hasNotCur, cur >> 1), best(hasCur, cur >> 1))
print(best(a, top))


n = int(input())
lis = list(map(int, input().split()))

def dfs(arr, pos):
	if pos < 0 or len(arr) == 0:
		return 0
	l1 = []
	l2 = []
	for i in arr:
		if i >> pos & 1 == 0:
			l1.append(i)
		else:
			l2.append(i)
	if not l1:
		return dfs(l2, pos - 1)
	elif not l2:
		return dfs(l1, pos - 1)
	else:
		return min(dfs(l1, pos - 1), dfs(l2, pos - 1)) + (1 << pos)
print(dfs(lis, 30))


def solve(nums, bit):
	if bit < 0:
		return 0
	l = []
	r = []
	for el in nums:
		if el >> bit & 1:
			r.append(el)
		else:
			l.append(el)
	if len(l) == 0:
		return solve(r, bit - 1)
	if len(r) == 0:
		return solve(l, bit - 1)
	return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit)
n = int(input())
nums = map(int, input().split())
print(solve(nums, 30))


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import sys
X = int(sys.stdin.readline())
a = set([int(i) for i in sys.stdin.readline().split()])
top = 1 << 31
ans = 0

def best(s, cur):
	if len(s) == 0 or cur == 0:
		return 0
	hasCur = set()
	hasNotCur = set()
	for i in s:
		if i & cur == 0:
			hasNotCur.add(i)
		else:
			hasCur.add(i)
	if len(hasNotCur) == 0 or len(hasCur) == 0:
		return best(s, cur >> 1)
	else:
		return cur + min(best(hasNotCur, cur >> 1), best(hasCur, cur >> 1))
print(best(a, top))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

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, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
from math import gcd
INF = 10 ** 18
MOD = 10 ** 9 + 7

def lcm(a, b):
	return a * b // gcd(a, b)

def solve(a, bits):
	if bits < 0:
		return 0
	l = []
	r = []
	for i in a:
		if i & 1 << bits > 0:
			l.append(i)
		else:
			r.append(i)
	if len(l) == 0:
		return solve(r, bits - 1)
	elif len(r) == 0:
		return solve(l, bits - 1)
	else:
		return min(2 ** bits + solve(l, bits - 1), 2 ** bits + solve(r, bits - 1))
n = int(ri())
a = Ri()
res = solve(a, 32)
print(res)


from bisect import bisect_left
input()
a = [int(i) for i in input().split()]
a.sort()

def f(i: int, j: int, bit: int):
	if bit < 0:
		return 0
	k = bisect_left(a, a[i] & -1 << bit | 1 << bit, i, j)
	if i < k < j:
		v = min(f(i, k, bit - 1), f(k, j, bit - 1)) | 1 << bit
	else:
		v = f(i, j, bit - 1)
	return v
print(f(0, len(a), 29))


n = int(input())
A = [int(s) for s in input().split()]
A.sort()
maxA = -1
for a in A:
	maxA = max(maxA, a)
priMask = 1
while priMask <= maxA:
	priMask <<= 1

def recur(start, end, mask):
	if mask == 0:
		return 0
	if A[start] & mask or not A[end] & mask:
		return recur(start, end, mask >> 1)
	low = start
	high = end
	while high - low > 1:
		mid = (low + high) // 2
		if A[mid] & mask:
			high = mid
		else:
			low = mid
	leftMin = recur(start, low, mask >> 1)
	rightMin = recur(high, end, mask >> 1)
	return mask + min(leftMin, rightMin)
ans = recur(0, n - 1, priMask)
print(ans)


def get_x(i, nums):
	get_ith_bit = lambda num: num >> i & 1
	(hi, lo) = ([], [])
	for num in nums:
		(hi if get_ith_bit(num) == 1 else lo).append(num)
	if hi and lo:
		if i == 0:
			return 1
		ith_bit = 1 << i
		explore_hi = get_x(i - 1, hi)
		explore_lo = get_x(i - 1, lo)
		next_bits = min(explore_hi, explore_lo)
	else:
		if i == 0:
			return 0
		ith_bit = 0
		next_bits = get_x(i - 1, nums)
	return ith_bit | next_bits
input()
nums = [int(n) for n in input().split()]
print(get_x(30, nums))


def solve(nums: set, bit: int):
	if len(nums) == 1:
		return 0
	lo = {x for x in nums if x & bit}
	hi = nums - lo
	if not lo:
		return solve(hi, bit >> 1)
	if not hi:
		return solve(lo, bit >> 1)
	return bit + min(solve(lo, bit >> 1), solve(hi, bit >> 1))
input()
nums = set(map(int, input().split()))
print(solve(nums, 1 << 30))


def argmin(a):
	if len(a[0]) == 0:
		return ('', 0)
	start_zeros = [item for item in a if item[0] == '0']
	start_ones = [item for item in a if item[0] == '1']
	if len(start_zeros) == 0:
		(a_ones, ans_ones) = argmin([item[1:] for item in start_ones])
		return ('1' + a_ones, ans_ones)
	if len(start_ones) == 0:
		(a_zeros, ans_zeros) = argmin([item[1:] for item in start_zeros])
		return ('0' + a_zeros, ans_zeros)
	(a_zeros, ans_zeros) = argmin([item[1:] for item in start_zeros])
	(a_ones, ans_ones) = argmin([item[1:] for item in start_ones])
	if ans_zeros < ans_ones:
		return ('1' + a_zeros, ans_zeros + int(2 ** (len(a[0]) - 1)))
	else:
		return ('0' + a_ones, ans_ones + int(2 ** (len(a[0]) - 1)))
n = int(input())
a = ['{0:b}'.format(item) for item in map(int, input().split())]
max_len = max([len(item) for item in a])
for i in range(n):
	a[i] = '0' * (max_len - len(a[i])) + a[i]
print(argmin(a)[1])


def answer(ans1, ans2):
	if max(len(ans1), len(ans2)) == 0:
		return 0
	if len(ans2) > 0 and len(ans1) == 0:
		(ans1, ans2) = (ans2, ans1)
	if len(ans1) > 0 and len(ans2) == 0:
		g1 = []
		g2 = []
		flag = 1
		for t in range(len(ans1[0])):
			k1 = []
			for j in range(len(ans1)):
				k1.append(ans1[j][t])
			if len(k1) != k1.count(k1[0]):
				flag = 0
				if t == len(ans1[0]) - 1:
					flag = 2
					break
				for i in range(len(ans1)):
					if ans1[i][t] == '0':
						g1.append(ans1[i][t + 1:])
					else:
						g2.append(ans1[i][t + 1:])
				break
		if flag == 2:
			return 1
		if flag == 0:
			if min(len(g1), len(g2)) == 0:
				return answer(g1, g2)
			else:
				return pow(2, len(g1[0])) + answer(g1, g2)
		else:
			return 0
	if len(ans1[0]) == 1:
		if min(len(ans1), len(ans2)) == 0:
			return 0
		elif len(ans1) == ans1.count(ans1[0]):
			return 0
		elif len(ans2) == ans2.count(ans2[0]):
			return 0
		else:
			return 1
	g1 = []
	g2 = []
	for i in range(len(ans1)):
		if ans1[i][0] == '1':
			g1.append(ans1[i][1:])
		else:
			g2.append(ans1[i][1:])
	x = answer(g1, g2)
	if min(len(g1), len(g2)) != 0:
		x += pow(2, len(g1[0]))
	g1 = []
	g2 = []
	for i in range(len(ans2)):
		if ans2[i][0] == '1':
			g1.append(ans2[i][1:])
		else:
			g2.append(ans2[i][1:])
	y = answer(g1, g2)
	if min(len(g1), len(g2)) != 0:
		y += pow(2, len(g1[0]))
	return min(x, y)

def calcu(ans):
	total = 0
	ans1 = []
	ans2 = []
	cnt1 = 0
	cnt2 = 0
	for i in range(len(ans)):
		if ans[i][0] == '0':
			ans1.append(ans[i][1:])
			cnt1 += 1
		else:
			ans2.append(ans[i][1:])
			cnt2 += 1
	if min(cnt1, cnt2) == 0:
		return answer(ans1, ans2)
	else:
		return pow(2, len(ans[i]) - 1) + answer(ans1, ans2)
a = int(input())
z = list(map(int, input().split()))
ans = []
for i in range(len(z)):
	t = bin(z[i])
	t = t[2:]
	t = '0' * (32 - len(t)) + t
	ans.append(t)
total = 0
print(calcu(ans))


import os
import sys
from io import BytesIO, IOBase

class TrieNode:

	def __init__(self):
		self.l = None
		self.r = None

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def insert(self, key):
		node = self.root
		for char in key:
			if char == '1':
				if not node.r:
					node.r = self.getNode()
				node = node.r
			else:
				if not node.l:
					node.l = self.getNode()
				node = node.l

	def getans(self):

		def solve(i, node):
			for j in range(i, -1, -1):
				(l, r) = (node.l, node.r)
				if l and r:
					return (1 << j) + min(solve(j - 1, l), solve(j - 1, r))
				elif l:
					node = l
				elif r:
					node = r
				else:
					return 0
			return 0
		return solve(29, self.root)

def main():
	n = int(input())
	if n == 1:
		print(0)
		exit()
	arr = list(map(lambda x: bin(int(x))[2:].zfill(30), input().split()))
	t = Trie()
	for item in arr:
		t.insert(item)
	print(t.getans())
BUFSIZE = 8192

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, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A.sort()
L = A[-1].bit_length()
canuse = [True] * N
ans = 0
for l in reversed(range(L)):
	Prob = set()
	for (i, a) in enumerate(A):
		if canuse[i]:
			Prob.add(a >> l ^ 1)
	must_add = True
	for (i, a) in enumerate(A):
		if canuse[i]:
			if not a >> l in Prob:
				must_add = False
				break
	if must_add:
		ans += 1 << l
	else:
		for (i, a) in enumerate(A):
			if canuse[i] and a >> l in Prob:
				canuse[i] = False
print(ans)


def recur(arr, val, pos):
	if pos == -1:
		return val
	on = []
	off = []
	for i in arr:
		if i & 1 << pos:
			on.append(i)
		else:
			off.append(i)
	if on and off:
		return min(recur(on, val + (1 << pos), pos - 1), recur(off, val + (1 << pos), pos - 1))
	elif on:
		return recur(on, val, pos - 1)
	else:
		return recur(off, val, pos - 1)
n = int(input())
arr = [int(x) for x in input().split()]
print(recur(arr, 0, 31))


import math
n = int(input())
a = list(map(int, input().strip().split()))

def solve(x, bit):
	if bit < 0:
		return 0
	(l, r) = ([], [])
	for i in range(len(x)):
		if x[i] & 1 << bit == 0:
			l.append(x[i])
		else:
			r.append(x[i])
	if len(l) == 0:
		return solve(r, bit - 1)
	if len(r) == 0:
		return solve(l, bit - 1)
	return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit)
print(solve(a, 30))


import bisect
BIG = 2 ** 31
n = int(input())
a = sorted(map(lambda s: -int(s), input().split()))
n = len(a)

def mv(a, l, r, cor, bs):
	if l + 1 == r:
		return 0
	elif l == r:
		return BIG
	elif a[l] == a[r - 1]:
		return 0
	corp = cor + 2 ** bs
	sep = bisect.bisect_right(a, -corp, l, r)
	lm = mv(a, l, sep, corp, bs - 1)
	rm = mv(a, sep, r, cor, bs - 1)
	if sep == l:
		return rm
	elif sep == r:
		return lm
	else:
		return min(lm, rm) + 2 ** bs
bs = (-a[0]).bit_length()
cor = 0
print(mv(a, 0, n, cor, bs - 1))


import sys
input = sys.stdin.readline

def calc(arr, b):
	if not arr or b < 0:
		return 0
	(bit1, bit0) = ([], [])
	for x in arr:
		if x >> b & 1:
			bit1.append(x)
		else:
			bit0.append(x)
	if not bit1:
		return calc(bit0, b - 1)
	elif not bit0:
		return calc(bit1, b - 1)
	else:
		return min(calc(bit1, b - 1), calc(bit0, b - 1)) + 2 ** b
n = int(input())
a = list(map(int, input().split()))
print(calc(a, 32))


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

def fun(arr, bit):
	if bit < 0:
		return 0
	z = []
	o = []
	for i in range(0, len(arr)):
		if arr[i] & 1 << bit == 0:
			z.append(arr[i])
		else:
			o.append(arr[i])
	if len(z) == 0:
		return fun(arr, bit - 1)
	if len(o) == 0:
		return fun(arr, bit - 1)
	return min(fun(z, bit - 1), fun(o, bit - 1)) + (1 << bit)
print(fun(a, 30))


def solve(c, bit):
	if not len(a) or bit < 0:
		return 0
	(l, r) = ([], [])
	for i in c:
		if i >> bit & 1 == 0:
			l.append(i)
		else:
			r.append(i)
	if not len(l):
		return solve(r, bit - 1)
	if not len(r):
		return solve(l, bit - 1)
	return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit)
n = int(input())
a = [int(x) for x in input().split()]
print(solve(a, 30))


n = int(input())
a = [int(x) for x in input().split(' ')]
a.sort()
b = pow(2, 30)
while b > 0 and a[n - 1] % b == a[n - 1]:
	b /= 2
b = int(b)
if b == 0:
	print(0)
	exit(0)

def sol(nums, lo, hi, bit):
	bit = int(bit)
	if bit < 1:
		return (nums[lo] % 2, 0)
	if hi - lo == 0:
		return (nums[lo] % (bit * 2), 0)
	ind = lo
	while ind <= hi and nums[ind] & bit != bit:
		ind += 1
	if ind - 1 - lo < 0:
		(x, maxi) = sol(nums, ind, hi, bit / 2)
		return (x + bit, maxi)
	elif hi - ind < 0:
		(x, maxi) = sol(nums, lo, ind - 1, bit / 2)
		return (x, maxi)
	else:
		(x_l, maxi_l) = sol(nums, lo, ind - 1, bit / 2)
		(x_r, maxi_r) = sol(nums, ind, hi, bit / 2)
		if maxi_l <= maxi_r:
			return (x_l + bit, maxi_l + bit)
		else:
			return (x_r, maxi_r + bit)
(X, ans) = sol(a, 0, n - 1, b)
print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):

	def getBest(i, j, k):
		hiBit = 1 << k - 1
		ones = []
		zeroes = []
		for index in range(i, j):
			x = A[index]
			if x & hiBit:
				ones.append(x)
			else:
				zeroes.append(x)
		assert i + len(zeroes) == j - len(ones)
		A[i:i + len(zeroes)] = zeroes
		A[j - len(ones):j] = ones
		if k == 1:
			if not ones or not zeroes:
				return 0
			return 1
		if not ones:
			return getBest(i, j, k - 1)
		elif not zeroes:
			return getBest(i, j, k - 1)
		else:
			ret = min(hiBit + getBest(i, i + len(zeroes), k - 1), hiBit + getBest(i + len(zeroes), j, k - 1))
			return ret
	return getBest(0, N, max(1, max(A).bit_length()))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


from sys import stdin
input = stdin.readline
n = int(input())
l = list(map(int, input().split()))
cyk = [1] * 50
for i in range(1, 50):
	cyk[i] = cyk[i - 1] * 2

def wyn(lista):
	m = max(lista)
	if m == min(lista):
		return 0
	le = len(bin(m))
	duze = []
	male = []
	pyk = cyk[le - 3]
	for i in lista:
		if i >= cyk[le - 3]:
			duze.append(i - pyk)
		else:
			male.append(i)
	if len(male) == 0:
		k = [lista[i] - pyk for i in range(len(lista))]
		return wyn(k)
	else:
		return pyk + min(wyn(duze), wyn(male))
print(wyn(l))


from math import floor, log

def get_x(i, nums):
	get_ith_bit = lambda num: num >> i & 1
	(hi, lo) = ([], [])
	for num in nums:
		(hi if get_ith_bit(num) == 1 else lo).append(num)
	if hi and lo:
		if i == 0:
			return 1
		ith_bit = 1 << i
		explore_hi = get_x(i - 1, hi)
		explore_lo = get_x(i - 1, lo)
		next_bits = min(explore_hi, explore_lo)
	else:
		if i == 0:
			return 0
		ith_bit = 0
		next_bits = get_x(i - 1, nums)
	return ith_bit | next_bits
input()
nums = [int(n) for n in input().split()]
print(get_x(29, nums))


n = int(input())
L = list(map(int, input().split()))

def solve(L, k):
	if k == 0:
		if 0 in L and 1 in L:
			return 1
		else:
			return 0
	bit = 2 ** k
	L0 = []
	L1 = []
	for i in L:
		if i >= bit:
			L1.append(i - bit)
		else:
			L0.append(i)
	if L0 == []:
		return solve(L1, k - 1)
	if L1 == []:
		return solve(L0, k - 1)
	sol0 = solve(L0, k - 1)
	sol1 = solve(L1, k - 1)
	return min(sol0, sol1) + bit
m = max(L)
t = 1
count = 0
while m > 1:
	m //= 2
	count += 1
print(solve(L, count))


def solve(lst, bit):
	if not len(lst) or bit < 0:
		return 0
	(ones, zeroes) = ([], [])
	for i in lst:
		if i >> bit & 1:
			ones.append(i)
		else:
			zeroes.append(i)
	if not len(ones):
		return solve(zeroes, bit - 1)
	if not len(zeroes):
		return solve(ones, bit - 1)
	return min(solve(ones, bit - 1), solve(zeroes, bit - 1)) + (1 << bit)
n = int(input())
aa = [int(i) for i in input().split()]
print(solve(aa, 30))


from os import name
from math import *

def dp(arr, bit):
	if bit < 0:
		return 0
	(a, b) = ([], [])
	for i in arr:
		if i & 1 << bit:
			a.append(i)
		else:
			b.append(i)
	if len(a) == 0:
		return dp(b, bit - 1)
	if len(b) == 0:
		return dp(a, bit - 1)
	return min(dp(a, bit - 1), dp(b, bit - 1)) + 2 ** bit

def pro(arr):
	print(dp(arr, 30))
n = int(input())
arr = list(map(int, input().split()))
pro(arr)


import math
from operator import and_, or_
from functools import reduce
import sys
sys.setrecursionlimit(100)

class Node:

	def __init__(self):
		self.left = None
		self.right = None

	def get_left(self):
		return self.left

	def get_right(self):
		return self.right

	def set_left(self, left):
		self.left = left

	def set_right(self, right):
		self.right = right
n = int(input())
arr = set(map(int, input().split()))
m = max(arr)
if m == 0:
	print(0)
	exit(0)
p = 1 << int(math.log2(max(arr)))
a = reduce(and_, arr)
b = reduce(or_, arr)
root = Node()
for x in arr:
	pi = p
	node = root
	while pi > 0:
		if x & pi:
			if node.get_right() == None:
				node.set_right(Node())
			node = node.get_right()
		else:
			if node.get_left() == None:
				node.set_left(Node())
			node = node.get_left()
		pi //= 2

def rec(node, pi):
	if pi == 0:
		return 0
	if node.get_left() == None:
		return rec(node.get_right(), pi // 2)
	elif node.get_right() == None:
		return rec(node.get_left(), pi // 2)
	else:
		return pi + min(rec(node.get_left(), pi // 2), rec(node.get_right(), pi // 2))
	return 0
print(rec(root, p))


import sys, os, io

def solve1():
	ans = 10 ** 18
	for i in range(130):
		curr = 0
		for j in a:
			curr = max(i ^ j, curr)
		ans = min(ans, curr)
	return ans

def fun(arr, ind):
	if len(arr) == 0 or ind < 0:
		return 0
	one = []
	zero = []
	for i in arr:
		if i[ind] == '1':
			one.append(i)
		else:
			zero.append(i)
	ans1 = fun(one, ind - 1)
	ans0 = fun(zero, ind - 1)
	if len(one) == 0:
		return ans0
	elif len(zero) == 0:
		return ans1
	return 2 ** ind + min(ans1, ans0)

def solve():
	cnt = [0] * 30
	b = []
	ma = max(a)
	l = len(bin(ma)) - 2
	for i in a:
		bi = bin(i)[2:]
		bi = '0' * (l - len(bi)) + bi
		bi = bi[::-1]
		b.append(bi)
	ans = fun(b, l - 1)
	return ans
n = 0
a = []
DEBUG = 0
if DEBUG:
	import random
	t = 100
	for _ in range(t):
		n = 10
		a = []
		for tt in range(n):
			a.append(random.randint(1, 64))
		ans1 = solve()
		ans2 = solve1()
		if ans1 != ans2:
			print(n)
			print(*a)
			print(ans1, ans2)
			break
else:
	pass
	n = int(input())
	a = [int(i) for i in input().split()]
	print(solve())


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

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, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = list(map(int, input().split()))

	def f(ar, bit, ans=0):
		if bit == -1:
			return ans
		a1 = []
		a2 = []
		for i in range(len(ar)):
			if ar[i] & 1 << bit:
				a1 += [ar[i]]
			else:
				a2 += [ar[i]]
		if not a2:
			return f(a1, bit - 1, ans)
		elif not a1:
			return f(a2, bit - 1, ans)
		else:
			(p, q) = (f(a1, bit - 1, ans + 2 ** bit), f(a2, bit - 1, ans + 2 ** bit))
			return min(p, q)
	x = f(a, 30)
	print(x)


n = int(input())
a = list(map(int, input().split()))
bit = []
for i in range(n):
	s = bin(a[i])[2:]
	if len(s) < 30:
		s = '0' * (30 - len(s)) + s
	bit.append(s)

def ans(p, j, an):
	if j == 30:
		return an
	if len(p) == 1:
		return an + '0' * (30 - j)
	d1 = []
	d0 = []
	for i in p:
		if bit[i][j] == '1':
			d1.append(i)
		else:
			d0.append(i)
	if len(d1) == 0:
		return ans(d0, j + 1, an + '0')
	elif len(d0) == 0:
		return ans(d1, j + 1, an + '0')
	return min(ans(d1, j + 1, an + '1'), ans(d0, j + 1, an + '1'))
print(int(ans([i for i in range(n)], 0, ''), 2))


def solve(v, bit):
	if len(v) == 0 or bit < 0:
		return 0
	l = list()
	r = list()
	for i in v:
		if i >> bit & 1 == False:
			l.append(i)
		else:
			r.append(i)
	if len(l) == 0:
		return solve(r, bit - 1)
	if len(r) == 0:
		return solve(l, bit - 1)
	return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit)
n = int(input())
arr = list(map(int, input().split()))
print(solve(arr, 30))


import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
import itertools, copy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
a.sort()
ln = a[-1].bit_length()
seg = [[0, n]]
res = 0
for i in range(ln):
	keta = ln - i - 1
	nx = []
	sp = []
	f = False
	for (s, t) in seg:
		if (a[s] >> keta) % 2 == (a[t - 1] >> keta) % 2:
			sp.append([s, t])
			f = True
		else:
			if f:
				continue
			for j in range(s, t - 1):
				if (a[j] >> keta) % 2 != (a[j + 1] >> keta) % 2:
					nx.append([s, j + 1])
					nx.append([j + 1, t])
					break
	if not f:
		seg = copy.deepcopy(nx)
		res += pow(2, keta)
	else:
		seg = copy.deepcopy(sp)
print(res)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n = int(input())
a = list(map(int, input().split()))
a.sort()
stack = [(0, n, 1 << 29, 0)]
ans = 1 << 30
while stack:
	(l, r, mask, curr) = stack.pop()
	if not mask:
		ans = min(ans, curr)
	elif not a[l] & mask and a[r - 1] & mask:
		L = l
		R = r - 1
		while L + 1 < R:
			m = L + R >> 1
			if a[m] & mask:
				R = m
			else:
				L = m
		m = R
		stack.append((l, m, mask >> 1, curr | mask))
		stack.append((m, r, mask >> 1, curr | mask))
	else:
		stack.append((l, r, mask >> 1, curr))
print(ans)


INF = 10 ** 10

def main():
	n = get_int()
	li = get_list()
	binaries = [bin(i)[2:].zfill(30) for i in li]

	def solve(li, lvl):
		if lvl == 30:
			return ''
		(l1, l2) = ([], [])
		for i in li:
			if binaries[i][lvl] == '0':
				l1.append(i)
			else:
				l2.append(i)
		if len(l1) == 0:
			return '0' + solve(l2, lvl + 1)
		elif len(l2) == 0:
			return '0' + solve(l1, lvl + 1)
		else:
			return '1' + min(solve(l1, lvl + 1), solve(l2, lvl + 1))
	print(int(solve(range(n), 0), 2))
import sys
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()


from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
a.sort()
pw = []
for i in range(31):
	pw.append(pow(2, i))
ans = 2 ** 31

def dfs(l, m, r, p, s):
	global ans
	if p == -2:
		ans = min(ans, s)
		return
	b0 = bisect_left(a, l)
	b1 = bisect_left(a, m)
	b2 = bisect_left(a, r)
	if b0 == b1 < b2:
		dfs(m, m + pw[p] if p >= 0 else 0, r, p - 1, s - pw[p + 1])
	elif b0 < b1 == b2:
		dfs(l, l + pw[p] if p >= 0 else 0, m, p - 1, s - pw[p + 1])
	elif b0 < b1 < b2:
		dfs(m, m + pw[p] if p >= 0 else 0, r, p - 1, s)
		dfs(l, l + pw[p] if p >= 0 else 0, m, p - 1, s)
dfs(0, pw[29], pw[30], 28, pw[30])
print(ans - 1)


n = int(input())
arr = list(map(int, input().split()))

def to_bin(n):
	return bin(n).replace('0b', '')
for i in range(n):
	arr[i] = to_bin(arr[i])
max_len = len(arr[0])
for i in arr:
	temp_len = len(i)
	if temp_len > max_len:
		max_len = temp_len
for i in range(n):
	arr[i] = '0' * (max_len - len(arr[i])) + arr[i]
arr.sort(reverse=True)

def max_x(i, l, r):
	if i == max_len:
		return ''
	for j in range(l, r + 1):
		if arr[j][i] == '0':
			if j != l:
				return min('1' + max_x(i + 1, j, r), '1' + max_x(i + 1, l, j - 1))
			else:
				return '0' + max_x(i + 1, j, r)
	return '0' + max_x(i + 1, l, r)
ans = max_x(0, 0, n - 1)
print(int(ans, 2))


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

def check(l, b):
	if b == 0:
		ans = int(not all(map(lambda x: x == l[0], l)))
		return ans
	l.sort()
	u = 0
	while u < len(l):
		if l[u] & 1 << b:
			break
		u += 1
	for i in range(len(l)):
		l[i] &= (1 << b) - 1
	if u == 0 or u == len(l):
		return check(l, b - 1)
	return 1 << b | min(check(l[:u], b - 1), check(l[u:], b - 1))
print(check(a, 31))


n = int(input())
nums = [int(x) for x in input().split(' ')]
totor = 0
for num in nums:
	totor |= num
exp = 1
while totor:
	exp <<= 1
	totor >>= 1
exp >>= 1

def ans(s, exp):
	if not exp:
		return 0
	ones = []
	zeros = []
	for e in s:
		if e >= exp:
			ones.append(e - exp)
		else:
			zeros.append(e)
	if not ones:
		return ans(zeros, exp >> 1)
	if not zeros:
		return ans(ones, exp >> 1)
	return exp + min(ans(zeros, exp >> 1), ans(ones, exp >> 1))
print(ans(nums, exp))


n = int(input())
a = list(map(int, input().split()))
maxim = cum = ans = 0
bitmask = 1
for ai in a:
	maxim = max(maxim, ai)
while bitmask <= maxim:
	bitmask <<= 1
bitmask >>= 1
consider = [1] * len(a)
while bitmask > 0:
	dic = {}
	for i in range(len(a)):
		if consider[i] == 0:
			continue
		if cum & a[i] not in dic.keys():
			dic[cum & a[i]] = a[i] & bitmask
		if dic[cum & a[i]] != a[i] & bitmask:
			dic[cum & a[i]] = -1
	to_pop = []
	for key in dic.keys():
		if dic[key] == -1:
			to_pop.append(key)
	for key in to_pop:
		dic.pop(key)
	if bool(dic):
		for i in range(len(a)):
			if consider[i] and cum & a[i] not in dic.keys():
				consider[i] = 0
	else:
		ans += bitmask
	cum |= bitmask
	bitmask >>= 1
print(ans)


def solve(group, bit):
	if bit == t - 1:
		for i in range(1, len(group)):
			if group[i][bit] != group[0][bit]:
				return 1
		return 0
	(g0, g1) = ([], [])
	for i in range(len(group)):
		if int(group[i][bit]):
			g1.append(group[i])
		else:
			g0.append(group[i])
	if len(g0) == 0:
		x.append('1')
		return solve(g1, bit + 1)
	elif len(g1) == 0:
		x.append('0')
		return solve(g0, bit + 1)
	else:
		s1 = solve(g0, bit + 1)
		s2 = solve(g1, bit + 1)
		if s1 < s2:
			x.append('1')
			return 2 ** (t - bit - 1) + s1
		else:
			x.append('0')
			return 2 ** (t - bit - 1) + s2
n = int(input())
l = list(map(int, input().split()))
l.sort()
t = len(bin(l[-1])[2:])
for i in range(n):
	b = bin(l[i])[2:]
	l[i] = '0' * (t - len(b)) + b
ans = []
x = []
print(solve(l, 0))


def main():
	n = int(input())
	a = readIntArr()

	def dfs(arr, bitShift):
		if bitShift == -1:
			return 0
		zeroes = []
		ones = []
		for x in arr:
			if x & 1 << bitShift > 0:
				ones.append(x)
			else:
				zeroes.append(x)
		if ones and zeroes:
			return 1 << bitShift | min(dfs(ones, bitShift - 1), dfs(zeroes, bitShift - 1))
		elif ones:
			return dfs(ones, bitShift - 1)
		else:
			return dfs(zeroes, bitShift - 1)
	ans = dfs(a, 29)
	print(ans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


n = int(input())
s = [int(x) for x in input().split()]

def rec(arr, bit):
	if bit < 0 or len(arr) == 0:
		return 0
	L1 = []
	L2 = []
	for i in range(0, len(arr)):
		if arr[i] >> bit & 1 == 1:
			L1.append(arr[i])
		else:
			L2.append(arr[i])
	if len(L1) == 0:
		return rec(L2, bit - 1)
	elif len(L2) == 0:
		return rec(L1, bit - 1)
	else:
		return min(rec(L1, bit - 1), rec(L2, bit - 1)) + (1 << bit)
print(rec(s, 29))


def dfs(s, k):
	if k < 0:
		return 0
	s1 = [i for i in s if i & ex2[k]]
	s0 = [i for i in s if i & ex2[k] == 0]
	if len(s1) == 0:
		return dfs(s0, k - 1)
	if len(s0) == 0:
		return dfs(s1, k - 1)
	return ex2[k] + min(dfs(s1, k - 1), dfs(s0, k - 1))
n = int(input())
s = list(map(int, input().split()))
ex2 = [2 ** i for i in range(31)]
print(dfs(s, 30))


t = int(input())
lst = [int(ele) for ele in input().split()]
maxn = max(lst)
n = len(bin(maxn)[2:])
newlst = ['0' * (n - len(bin(ele)[2:])) + bin(ele)[2:] for ele in lst]

def catchEvil(lstrino, loc):
	(count0, count1) = ([], [])
	for ele in lstrino:
		if ele[n - 1 - loc] == '1':
			count1.append(ele)
		else:
			count0.append(ele)
	if len(count0) == 0:
		if loc == 0:
			return 0
		else:
			return catchEvil(lstrino, loc - 1)
	elif len(count1) == 0:
		if loc == 0:
			return 0
		else:
			return catchEvil(lstrino, loc - 1)
	elif loc == 0:
		return 1
	else:
		return min(catchEvil(count1, loc - 1), catchEvil(count0, loc - 1)) + (1 << loc)
if n == 0:
	print(0)
else:
	print(int(catchEvil(newlst, n - 1)))


def dp(bit, arr, left, right):
	if bit == -1:
		return (0, 0)
	mask = 1 << bit
	piv = None
	for i in range(left, right):
		if arr[i] & mask:
			piv = i
			break
	if piv is None:
		(ans, msk) = dp(bit - 1, arr, left, right)
		return (ans, msk + mask)
	if piv == left:
		(ans, msk) = dp(bit - 1, arr, left, right)
		return (ans, msk)
	(ans_0, msk_0) = dp(bit - 1, arr, left, piv)
	(ans_1, msk_1) = dp(bit - 1, arr, piv, right)
	if ans_0 < ans_1:
		return (ans_0 + mask, msk_0 + mask)
	else:
		return (ans_1 + mask, msk_1)
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
(ans, mask) = dp(30, arr, 0, n)
print(ans)


def rec(l, bit):
	if bit < 0:
		return 0
	e1 = []
	e2 = []
	for i in l:
		if i >> bit & 1 == 0:
			e1.append(i)
		else:
			e2.append(i)
	if len(e1) == 0:
		return rec(e2, bit - 1)
	if len(e2) == 0:
		return rec(e1, bit - 1)
	return min(rec(e2, bit - 1), rec(e1, bit - 1)) + 2 ** bit
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	print(rec(l, 32))


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

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys

def search(b, bit):
	if bit < 0 or len(b) == 0:
		return 0
	r = []
	l = []
	for x in b:
		if x >> bit & 1 == 1:
			r.append(x)
		else:
			l.append(x)
	if len(l) == 0:
		return search(r, bit - 1)
	if len(r) == 0:
		return search(l, bit - 1)
	return min(search(r, bit - 1), search(l, bit - 1)) + 2 ** bit
n = I()
a = L()
print(search(a, 30))


def solve(a, b=32):
	if b == -1:
		return 0
	a1 = []
	a2 = []
	n = len(a)
	for i in range(n):
		if a[i] // 2 ** b % 2 == 1:
			a1.append(a[i])
		else:
			a2.append(a[i])
	if len(a1) == 0:
		return solve(a2, b - 1)
	elif len(a2) == 0:
		return solve(a1, b - 1)
	else:
		return 2 ** b + min(solve(a1, b - 1), solve(a2, b - 1))
n = int(input())
a = list(map(int, input().split()))
print(solve(a))


def solve(c, b):
	if not len(lis) or b < 0:
		return 0
	(l, r) = ([], [])
	for i in c:
		if i >> b & 1 == 0:
			l.append(i)
		else:
			r.append(i)
	if not len(l):
		return solve(r, b - 1)
	if not len(r):
		return solve(l, b - 1)
	return min(solve(l, b - 1), solve(r, b - 1)) + (1 << b)
n = int(input())
lis = list(map(int, input().split()))
print(solve(lis, 30))


from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
import math

def solve(arr, bit):
	if len(arr) == 0 or bit < 0:
		return 0
	l = []
	r = []
	for i in arr:
		if i >> bit & 1 == 0:
			l.append(i)
		else:
			r.append(i)
	if len(l) == 0:
		return solve(r, bit - 1)
	if len(r) == 0:
		return solve(l, bit - 1)
	return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit)
n = int(input().strip())
arr = list(map(int, input().split()))
print(solve(arr, 30))


mx = 32

def f(a, pos):
	if pos < 0 or len(a) == 0:
		return 0
	on = []
	off = []
	for x in a:
		if x & 1 << pos:
			on.append(x)
		else:
			off.append(x)
	if len(on) == 0:
		return f(off, pos - 1)
	if len(off) == 0:
		return f(on, pos - 1)
	a.clear()
	return (1 << pos) + min(f(on, pos - 1), f(off, pos - 1))

def solve(n):
	li = list(map(int, input().split()))
	print(f(li, mx))
while True:
	try:
		n = int(input())
		solve(n)
	except EOFError:
		break


def get_bit(val, id):
	return val >> id & 1
trie = []

def new_node():
	trie.append([-1] * 2)

def add(val):
	indx = 0
	for i in range(30, -1, -1):
		x = get_bit(val, i)
		if trie[indx][x] == -1:
			new_node()
			trie[indx][x] = len(trie) - 1
		indx = trie[indx][x]

def DFS(bit, u):
	if bit < 0:
		return 0
	ans0 = int(2 ** 30)
	ans1 = int(2 ** 30)
	if trie[u][0] != -1:
		ans0 = DFS(bit - 1, trie[u][0])
	if trie[u][1] != -1:
		ans1 = DFS(bit - 1, trie[u][1])
	if trie[u][0] != -1 and trie[u][1] != -1:
		return min(ans0, ans1) + (1 << bit)
	return min(ans0, ans1)
n = int(input())
new_node()
a = list(map(int, input().split()))
for i in range(n):
	add(a[i])
print(DFS(30, 0))


import sys
input = lambda : sys.stdin.readline().rstrip()

def dr_evil(a, l):
	b0 = []
	b1 = []
	for i in a:
		if i & 1 << l:
			b1.append(i)
		else:
			b0.append(i)
	if len(b0) == 0:
		if l == 0:
			return 0
		else:
			return dr_evil(b1, l - 1)
	elif len(b1) == 0:
		if l == 0:
			return 0
		else:
			return dr_evil(b0, l - 1)
	else:
		if l == 0:
			return 1
		return min(dr_evil(b0, l - 1), dr_evil(b1, l - 1)) + (1 << l)
n = int(input())
A = [int(i) for i in input().split()]
l = max(A).bit_length()
if l == 0:
	print(0)
else:
	print(dr_evil(A, l - 1))


import sys

def f(a, bit):
	if len(a) == 0 or bit < 0:
		return 0
	(l, r) = (list(), list())
	x = 1 << bit
	for i in a:
		if x & i > 0:
			r.append(i)
		else:
			l.append(i)
	if len(l) == 0:
		return f(r, bit - 1)
	if len(r) == 0:
		return f(l, bit - 1)
	return min(f(l, bit - 1), f(r, bit - 1)) + x

def main():
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	print(f(a, 30))
main()


import math, collections, sys
input = sys.stdin.readline

def solve(a, bit):
	if len(a) == 0 or bit < 0:
		return 0
	one = []
	zero = []
	for i in a:
		if i >> bit & 1:
			one.append(i)
		else:
			zero.append(i)
	if not one:
		return solve(zero, bit - 1)
	if not zero:
		return solve(one, bit - 1)
	return min(solve(one, bit - 1), solve(zero, bit - 1)) + (1 << bit)
n = int(input())
z = list(map(int, input().split()))
print(solve(z, 30))


def maxxor(A, n):
	if len(A) == 1:
		return 0
	if n == -1:
		return 0
	one = 0
	zero = 0
	res = 0
	for a in A:
		one += a >> n & 1
		zero += 1 - (a >> n & 1)
	if one == 0 or zero == 0:
		return maxxor(A, n - 1)
	else:
		B = [A[i] for i in range(len(A)) if A[i] >> n & 1 == 1]
		C = [A[i] for i in range(len(A)) if A[i] >> n & 1 == 0]
		m = min(maxxor(B, n - 1), maxxor(C, n - 1))
		return m + 2 ** n
import random
N = int(input())
A = list(map(int, input().split()))
print(maxxor(A, 30))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))

def solve(a, l):
	bit0 = []
	bit1 = []
	for elem in a:
		if elem & 1 << l:
			bit1.append(elem)
		else:
			bit0.append(elem)
	if len(bit0) == 0:
		if l == 0:
			return 0
		else:
			return solve(bit1, l - 1)
	elif len(bit1) == 0:
		if l == 0:
			return 0
		else:
			return solve(bit0, l - 1)
	elif l == 0:
		return 1
	else:
		return min(solve(bit1, l - 1), solve(bit0, l - 1)) + (1 << l)
l = max(a).bit_length()
if l == 0:
	print(0)
else:
	print(solve(a, l - 1))


from sys import stdin, setrecursionlimit
setrecursionlimit(pow(10, 9))

def input():
	return stdin.readline().strip()

def solve(c, bit):
	if bit < 0:
		return 0
	(l, r) = ([], [])
	for ele in c:
		if ele >> bit & 1 == 0:
			l.append(ele)
		else:
			r.append(ele)
	if len(l) == 0:
		return solve(r, bit - 1)
	if len(r) == 0:
		return solve(l, bit - 1)
	return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit)
n = int(input())
arr = list(map(int, input().split()))
ans = solve(arr, 30)
print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
a = list(map(int, input().split()))

def calc(lis, keta):
	mask = 1 << keta
	one = []
	zer = []
	for ai in lis:
		if mask & ai:
			one.append(ai)
		else:
			zer.append(ai)
	if keta == 0:
		if len(one) * len(zer) == 0:
			return 0
		else:
			return 1
	else:
		ret = 0
		if len(one) * len(zer) != 0:
			ret += mask
			ret += min(calc(one, keta - 1), calc(zer, keta - 1))
		elif one:
			ret = calc(one, keta - 1)
		else:
			ret = calc(zer, keta - 1)
		return ret
ans = calc(a, 31)
print(ans)


import sys

def solve(arr, bit):
	if len(arr) == 0 or bit < 0:
		return 0
	(l, r) = ([], [])
	for i in range(len(arr)):
		if arr[i] >> bit & 1 == 0:
			l.append(arr[i])
		else:
			r.append(arr[i])
	if len(l) == 0:
		return solve(r, bit - 1)
	if len(r) == 0:
		return solve(l, bit - 1)
	return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit)
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
print(solve(l, 33))