#include<bits/stdc++.h>
using namespace std;
bool  compare(int a,int b){
	return a>b;
}
int main(){
	int n,a[1005];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int sum1= 0,sum2=0;
	sort(a,a+n,compare);
	if(n%2==0){
		for(int i=0;i<n;i +=2){
			sum1 += a[i];
		}
		for(int i=1;i<n;i +=2){
			sum2 += a[i];
		}
	}
	else{
		for(int i=0;i<n;i+=2){
			sum1 += a[i];
		}
		for(int i=1;i<n;i+=2){
			sum2 += a[i];
		}
	}
	cout << sum1<<" "<< sum2;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[1005];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int sum1= 0,sum2=0;
	sort(a,a+n);
	if(n%2==0){
		for(int i=1;i<n;i +=2){
			sum1 += a[i];
		}
		for(int i=0;i<n;i +=2){
			sum2 += a[i];
		}
	}
	else{
		for(int i=0;i<n;i+=2){
			sum1 += a[i];
		}
		for(int i=1;i<n;i+=2){
			sum2 += a[i];
		}
	}
	cout << sum1<< sum2;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[1005];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int sum1= 0,sum2=0;
	sort(a,a+n);
	if(n%2==0){
		for(int i=1;i<n;i +=2){
			sum1 += a[i];
		}
		for(int i=0;i<n;i +=2){
			sum2 += a[i];
		}
	}
	else{
		for(int i=0;i<n;i+=2){
			sum1 += a[i];
		}
		for(int i=1;i<n;i+=2){
			sum2 += a[i];
		}
	}
	cout << sum1<<" "<< sum2;
}


#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,s=0,d=0;
	cin>>n;
	int arr[100];
	for(int i=0; i<n; i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr + n);
	reverse(arr, arr + n);
	for(int i=0; i<n; i+=2)
	{
		 s += arr[i];
	}
	for(int i=1; i<n; i+=2)
	{
		 d += arr[i];
	}
	cout<<s<<" "<<d<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int s = 0, d = 0;
	cin >> n;
	int arr[1000];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	sort(arr, arr + n);
	reverse(arr, arr + n);
	for (int i = 0; i < n; i += 2)
	{
		s += arr[i];
	}
	for (int i = 1; i <n; i += 2)
	{
		d += arr[i];
	}
	cout << s << " " << d;
    return 0;
}


#include<iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,s=0,d=0;
	cin>>n;
	int arr[1000];
	for(int i=0; i<n; i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr + n);
	reverse(arr, arr + n);
	for(int i=0; i<n; i+=2)
	{
		 s += arr[i];
	}
	for(int i=1; i<n; i+=2)
	{
		 d += arr[i];
	}
	cout<<s<<" "<<d<<endl;
	return 0;
}


#include<iostream>
#include <vector>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<deque>
using namespace std;
int main()
{
	int n;
	cin >> n;
	deque<int> d;
	int value;
	int z = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> value;
		d.push_back(value);
	}
	int totalS = 0, totalD = 0;
		int S, D;
	while (!d.empty())
	{

		S = d.front();
		D = d.back();
		if (S >= D)
		{
			if (z == 0)
			{
				totalS += S;

			}
			else
			{
				totalD += S;
			}
			d.pop_front();

		}
		else
		{
			if (z == 0)
			{
				totalS += D;
			}
			else
			{
				totalD += D;
			}
			d.pop_back();
		}
		z = 1 - z;
	}
	cout << totalS << " " << totalD;
	return 0;
}


#include<iostream>
#include <vector>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
using namespace std;
int main()
{
	int n;
	int s = 0, d = 0;
	cin >> n;
	int arr[1000];
	for (int i = 0; i < n; i++)1
	{
		cin >> arr[i];
	}
	sort(arr, arr + n);
	reverse(arr, arr + n);
	for (int i = 0; i < n; i += 2)
	{
		s += arr[i];
	}
	for (int i = 1; i <n; i += 2)
	{
		d += arr[i];
	}
	cout << s << " " << d;
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
vector<int>a;
int ans(vector<int>&c, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<int>r, l;
	for (int i = 0; i < c.size(); i++)
	{
		if (((c[i] >> bit) & 1)== 0)l.push_back(c[i]);
		else r.push_back(c[i]);
	}
	if (!l.size())return ans(r, bit - 1);
	else if (!r.size())return ans(l, bit - 1);
	else return min(ans(l, bit - 1), ans(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	int n, i = 0,p; cin >> n;
	while (i < n)cin >> p,a.push_back(p);
	cout << (a.size()?ans(a, 30):0) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
vector<int>a;
int ans(vector<int>&c, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<int>r, l;
	for (int i = 0; i < c.size(); i++)
	{
		if (((c[i] >> bit) & 1)== 0)l.push_back(c[i]);
		else r.push_back(c[i]);
	}
	if (!l.size())return ans(r, bit - 1);
	else if (!r.size())return ans(l, bit - 1);
	else return min(ans(l, bit - 1), ans(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	int n, i = 0,p; cin >> n;
	while (a.size() != n)cin >> p; a.push_back(p);
	cout << (a.size()?ans(a, 30):0) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
ll tree(vector<ll>a, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<ll>r, l;
	for (size_t i = 0; i < a.size(); i++)
	{
		if ((a[i] ^ (int)pow(2, bit)) > a[i])l.push_back(a[i]);
		else r.push_back(a[i]);
	}
	if (!l.size())return tree(r, bit - 1);
	else if (!r.size())return tree(l, bit - 1);
	else return min(tree(l, bit - 1), tree(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	ll n, i = 0; cin >> n;
	vector<ll>a(n);
	while (i < n)cin >> a[i++];
	cout << tree(a, 30) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
vector<int>a;
int ans(vector<int>&c, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<int>r, l;
	for (int i = 0; i < c.size(); i++)
	{
		if (((c[i] >> bit) & 1)== 0)l.push_back(c[i]);
		else r.push_back(c[i]);
	}
	if (!l.size())return ans(r, bit - 1);
	else if (!r.size())return ans(l, bit - 1);
	else return min(ans(l, bit - 1), ans(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	int n, i = 0; cin >> n;
	while (i < n)cin >> a[i++];
	cout << (a.size()?ans(a, 30):0) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
int tree(vector<int>a, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<int>r, l;
	for (size_t i = 0; i < a.size(); i++)
	{
		if ((a[i] ^ (int)pow(2, bit)) > a[i])l.push_back(a[i]);
		else r.push_back(a[i]);
	}
	if (!l.size())return tree(r, bit - 1);
	else if (!r.size())return tree(l, bit - 1);
	else return min(tree(l, bit - 1), tree(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	int n, i = 0; cin >> n;
	vector<int>a(n);
	while (i < n)cin >> a[i++];
	cout << tree(a, 30) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
vector<int>a;
int ans(vector<int>&c, int bit)
{
	if (!a.size() || bit<0)return 0;
	vector<int>r, l;
	for (int i = 0; i < c.size(); i++)
	{
		if (((c[i] >> bit) & 1)== 0)l.push_back(c[i]);
		else r.push_back(c[i]);
	}
	if (!l.size())return ans(r, bit - 1);
	else if (!r.size())return ans(l, bit - 1);
	else return min(ans(l, bit - 1), ans(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	int n, i = 0,p; cin >> n;
	while (i < n) { cin >> p; a.push_back(p); ++i; }
	cout << (a.size()?ans(a, 30):0) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
vector<int>a;
int ans(vector<int>&c, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<int>r, l;
	for (int i = 0; i < c.size(); i++)
	{
		if (((c[i] >> bit) & 1)== 0)l.push_back(c[i]);
		else r.push_back(c[i]);
	}
	if (!l.size())return ans(r, bit - 1);
	else if (!r.size())return ans(l, bit - 1);
	else return min(ans(l, bit - 1), ans(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	int n, i = 0,p; cin >> n;
	while (i < n) { cin >> p; a.push_back(p); ++i; }
	cout << (a.size()?ans(a, 30):0) << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

int solve(vector <int> &c, int bit){
    if(a.size() == 0 || bit < 0) return 0;
    vector <int> l, r;
    for(auto &i : c){
        if(((i >> bit) & 1) == 0) l.push_back(i);
        else r.push_back(i);
    }
    if(l.size() == 0) return solve(r, bit - 1);
    if(r.size() == 0) return solve(l, bit - 1);
    return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    cout << solve(a, 30) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
ll tree(vector<ll>&a, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<ll>r, l;
	for (size_t i = 0; i < a.size(); i++)
	{
		if (((a[i] >> bit) & 1)== 0)l.push_back(a[i]);
		else r.push_back(a[i]);
	}
	if (!l.size())return tree(r, bit - 1);
	else if (!r.size())return tree(l, bit - 1);
	else return min(tree(l, bit - 1), tree(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	ll n, i = 0; cin >> n;
	vector<ll>a(n);
	while (i < n)cin >> a[i++];
	cout << tree(a, 30) << endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <functional>
#include <map>
#include <set>
//
using namespace std;
typedef long long int ll;
typedef long long unsigned int llu;
const ll MAX = 100000;
//
ll tree(vector<ll>&a, int bit)
{
	if (!a.size() || !bit)return 0;
	vector<ll>r, l;
	for (size_t i = 0; i < a.size(); i++)
	{
		if ((a[i] << bit) & 1 == 0)l.push_back(a[i]);
		else r.push_back(a[i]);
	}
	if (!l.size())return tree(r, bit - 1);
	else if (!r.size())return tree(l, bit - 1);
	else return min(tree(l, bit - 1), tree(r, bit - 1)) + (1 << bit);
}
//
int main()
{
	ll n, i = 0; cin >> n;
	vector<ll>a(n);
	while (i < n)cin >> a[i++];
	cout << tree(a, 30) << endl;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN], mn;
vector<int> all;

void f(int x, vector<int> &v, int xr = 0) {
	if (x == -1) {
		int mx = 0;
		for (auto i : v) {
			mx = max(a[i] ^ xr, mx);
		}
		mn = min(mn, mx);
		return;
	}
	vector<int> help1;
	vector<int> help2;
	for (auto i : v)
		if ((a[i] & (1 << x)) != 0)
			help1.pb(i);
		else
			help2.pb(i);
	if (help1.size() == 0)
		f(x - 1, help2, xr);
	else if (help2.size() == 0)
		f(x - 1, help1, xr ^ (1 << x));
	else
		f(x - 1, help1, xr), f(x - 1, help2, xr ^ (1 << x));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], all.pb(i), mn = max(a[i], mn);
	f(30, all);
	cout << mn << endl;
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN], mn;

void f(int x, int l = 1, int r = n + 1, int xr = 0) {
	if (l >= r)
		return;
	if (x == -1) {
		mn = min(mn, a[l] ^ xr);
		return;
	}
	int pnt = r;
	for (int i = l; i < r; i++)
		if ((a[i] & (1 << x)) != 0) {
			pnt = i;
			break;
		}
	if (pnt == r)
		f(x - 1, l, r, xr);
	else if (pnt == l)
		f(x - 1, l, r, xr ^ (1 << x));
	else
		f(x - 1, pnt, r, xr), f(x - 1, l, pnt, xr ^ (1 << x));
	return;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], mn = max(a[i], mn);
	sort(a + 1, a + n + 1);
	f(log2(mn));
	cout << mn << endl;
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN];

int f(int x, int l = 1, int r = n + 1, int xr = 0) {
	if (l >= r)
		return 2e9 + 17;
	if (x == -1)
		return a[l] ^ xr;
	int pnt = r;
	for (int i = l; i < r; i++)
		if ((a[i] & (1 << x)) != 0) {
			pnt = i;
			break;
		}
	if (pnt == r)
		return f(x - 1, l, r, xr);
	else if (pnt == l)
		return f(x - 1, l, r, xr ^ (1 << x));
	else
		return min(f(x - 1, pnt, r, xr), f(x - 1, l, pnt, xr ^ (1 << x)));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	cout << f(30) << endl;
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN];

void f(int x, int l = 1, int r = n + 1, int xr = 0) {
	if (l >= r)
		return 2e9 + 17;
	if (x == -1)
		return a[l] ^ xr;
	int pnt = r;
	for (int i = l; i < r; i++)
		if ((a[i] & (1 << x)) != 0) {
			pnt = i;
			break;
		}
	if (pnt == r)
		return f(x - 1, l, r, xr);
	else if (pnt == l)
		return f(x - 1, l, r, xr ^ (1 << x));
	else
		return min(f(x - 1, pnt, r, xr), f(x - 1, l, pnt, xr ^ (1 << x)));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], mn = max(a[i], mn);
	sort(a + 1, a + n + 1);
	cout << f(log2(mn)) << endl;
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN], mn;

void f(int x, int l = 1, int r = n + 1, int xr = 0) {
	if (l >= r)
		return;
	if (x == -1) {
		mn = min(mn, a[l] ^ xr);
		return;
	}
	int pnt = r;
	for (int i = l; i < r; i++)
		if ((a[i] & (1 << x)) != 0) {
			pnt = i;
			break;
		}
	if (pnt == r) {
		f(x - 1, l, r, xr);
		return;
	}
	else if (pnt == l) {
		f(x - 1, l, r, xr ^ (1 << x));
		return;
	}
	else {
		f(x - 1, pnt, r, xr), f(x - 1, l, pnt, xr ^ (1 << x));
		return;
	}
	return;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], mn = max(a[i], mn);
	sort(a + 1, a + n + 1);
	f(log2(mn));
	cout << mn << endl;
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN], mn;

void f(int x, int l = 1, int r = n + 1, int xr = 0) {
	if (x == -1) {
		int mx = 0;
		for (int i = l; i < r; i++)
			mx = max(a[i] ^ xr, mx);
		mn = min(mn, mx);
		return;
	}
	int pnt = r;
	for (int i = l; i < r; i++)
		if ((a[i] & (1 << x)) != 0) {
			pnt = i;
			break;
		}
	if (pnt == r)
		f(x - 1, l, r, xr);
	else if (pnt == l)
		f(x - 1, l, r, xr ^ (1 << x));
	else
		f(x - 1, pnt, r, xr), f(x - 1, l, pnt, xr ^ (1 << x));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], mn = max(a[i], mn);
	sort(a + 1, a + n + 1);
	f(log2(mn));
	cout << mn << endl;
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN], mn;
vector<int> all;

int f(int x, vector<int> &v, int xr = 0) {
	if (x == -1)
		return a[v[0]] ^ xr;
	vector<int> help1;
	vector<int> help2;
	for (auto i : v)
		if ((a[i] & (1 << x)) != 0)
			help1.pb(i);
		else
			help2.pb(i);
	if (help1.size() == 0)
		return f(x - 1, help2, xr);
	else if (help2.size() == 0)
		return f(x - 1, help1, xr ^ (1 << x));
	else
		return min(f(x - 1, help1, xr), f(x - 1, help2, xr ^ (1 << x)));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], all.pb(i);
	cout << f(30, all);
	return 0;
}


//IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 * 1000 + 17;

int n, a[MAXN], mn;

void f(int x, int l = 1, int r = n + 1, int xr = 0) {
	if (l >= r)
		return;
	if (x == -1) {
		mn = min(mn, a[l] ^ xr);
		return;
	}
	int pnt = r;
	for (int i = l; i < r; i++)
		if ((a[i] & (1 << x)) != 0) {
			pnt = i;
			break;
		}
	if (pnt == r)
		f(x - 1, l, r, xr);
	else if (pnt == l)
		f(x - 1, l, r, xr ^ (1 << x));
	else
		f(x - 1, pnt, r, xr), f(x - 1, l, pnt, xr ^ (1 << x));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], mn = max(a[i], mn);
	sort(a + 1, a + n + 1);
	f(log2(mn));
	cout << mn << endl;
	return 0;
}


/*input

2 1 5

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n],k[n];
	rep(i,0,n){
		cin>>a[i];
		k[i]=a[i];
	}
	ll x=0;
	ll x1=1;
	repi(j,31,-1){
		ll a1=0,b1=0,c1=1<<j,c=0;
		rep(i,0,n){
			if(c1&a[i]){
				c++;
			}
		}
		//cout<<c<<endl;
		if(c==n){
			rep(i,0,n){
				a[i]^=c1;
			}
			continue;
		}
		if(!c)
			continue;
		if(x1){
			x1=0;
			x+=c1;
		}else{
			x1=1;
		}

	}

	cout<<x<<endl;
	return 0;
}


/*input

3 1 2 3

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n],k[n];
	rep(i,0,n){
		cin>>a[i];
		k[i]=a[i];
	}
	ll x=0;
	ll x1=-1;
	ll b[n];
	init(b,n,1);
	repi(j,31,-1){
		ll a1=0,b1=0,c1=1<<j,c=0,c2=0;
		rep(i,0,n){

			if(b[i]&&!(c1&a[i])){
				c++;
			}else if(b[i]&&(c1&a[i])){
				c2++;
			}
			if(c&&c2)
				break;
		}
		//cout<<c<<endl;
		if(i==n){
			x1=-1;
			continue;
		}
		if(x1==-1){
			x+=c1;
			x1=c1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		x+=c1;

	}

	cout<<x<<endl;
	return 0;
}


/*input

3 1 2 3

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n],k[n];
	rep(i,0,n){
		cin>>a[i];
		k[i]=a[i];
	}
	ll x=0;
	ll x1=-1;
	ll b[n];
	init(b,n,1);
	repi(j,31,-1){
		ll a1=0,b1=0,c1=1<<j,c=0;
		rep(i,0,n){
			if(c1&a[i]){
				c++;
			}
		}
		//cout<<c<<endl;
		if(c==n){
			rep(i,0,n){
				a[i]^=c1;
			}
			continue;
		}
		if(!c)
			continue;
		if(x1==-1){
			x+=c1;
			x1=c1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		x+=c1;
		x1=c1;

	}

	cout<<x<<endl;
	return 0;
}


/*input
5 1 4
*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}
ll func(ll j,vll &a){
	if(j<0)
		return 0;
	ll i;
	ll n=a.size();
	ll c1=0;
	ll k=1<<j;
	rep(i,0,n){
		if(a[i]&k){
			c1++;
		}
	}
	if(c1==0||c1==n){
		return func(j-1,a);
	}
	vll b,c;
	rep(i,0,n){
		if(a[i]&k)
		b.pb(a[i]);
		else
		c.pb(a[i]);
	}
	return k+min(func(j-1,b),func(j-1,c));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	vll a(n);
	rep(i,0,n){
		cin>>a[i];
	}
	cout<<func(31,a);
	return 0;
}


/*input

2 1 5

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n],k[n];
	rep(i,0,n){
		cin>>a[i];
		k[i]=a[i];
	}
	ll x=0;
	ll x1=-1;
	ll b[n];
	init(b,n,1);
	repi(j,31,-1){
		ll a1=0,b1=0,c1=1<<j,c=0,c2=0;
		rep(i,0,n){

			if(b[i]&&!(c1&a[i])){
				c++;
			}else if(b[i]&&(c1&a[i])){
				c2++;
			}
			if(c&&c2)
				break;
		}
		//cout<<c<<endl;
		if(i==n){
			continue;
		}
		if(x1==-1){
			x+=c1;
			x1=c1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=c1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=c1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=c1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=c1;
			continue;
		}
		x+=c1;

	}

	cout<<x<<endl;
	return 0;
}


/*input
2 1 5

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n],k[n];
	rep(i,0,n){
		cin>>a[i];
		k[i]=a[i];
	}
	ll x=0;
	repi(j,30,-1){
		ll a1=0,b1=0,c1=1<<j,c=0;
		rep(i,0,n){
			if(c1&a[i]){
				a1=max(a1,a[i]);
				c++;
			}else{
				b1=max(b1,a[i]);
			}
		}
		//cout<<c<<endl;
		if(c==n){
			//cout<<x<<endl;
			x+=c1;
			rep(i,0,n){
				a[i]^=c1;
			}
			continue;
		}if(!c){

			continue;
		}
		//cout<<a1<<" "<<b1<<" "<<c1<<endl;
		if(max(a1,b1)>=max(a1-c1,b1+c1)){
			//cout<<x<<endl;
			x+=c1;
			rep(i,0,n){
				a[i]^=c1;
			}
		}

	}
	ll ans=0;
	rep(i,0,n){
		ans=max(ans,x^k[i]);
	}
	//cout<<x<<endl;
	cout<<ans<<endl;
	return 0;
}


/*input
3 1 2 3

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n],k[n];
	rep(i,0,n){
		cin>>a[i];
		k[i]=a[i];
	}
	ll x=0;
	rep(j,0,31){
		ll a1=0,b1=0,c1=1<<j,c=0;
		rep(i,0,n){
			if(c1&a[i]){
				a1=max(a1,a[i]);
				c++;
			}else{
				b1=max(b1,a[i]);
			}
		}
		//cout<<c<<endl;
		if(c==n){
			//cout<<x<<endl;
			x+=c1;
			rep(i,0,n){
				a[i]^=c1;
			}
			continue;
		}if(!c){

			continue;
		}
		//cout<<a1<<" "<<b1<<" "<<c1<<endl;
		if(max(a1,b1)>=max(a1-c1,b1+c1)){
			//cout<<x<<endl;
			x+=c1;
			rep(i,0,n){
				a[i]^=c1;
			}
		}

	}
	ll ans=0;
	rep(i,0,n){
		ans=max(ans,x^k[i]);
	}
	//cout<<x<<endl;
	cout<<ans<<endl;
	return 0;
}


/*input

3 1 2 3

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a[n],k[n];
	rep(i,0,n){
		cin>>a[i];
		k[i]=a[i];
	}
	ll x=0;
	ll x1=-1;
	ll b[n];
	init(b,n,1);
	repi(j,31,-1){
		ll a1=0,b1=0,c1=1<<j,c=0,c2=0;
		rep(i,0,n){

			if(b[i]&&!(c1&a[i])){
				c++;
			}else if(b[i]&&(c1&a[i])){
				c2++;
			}
			if(c&&c2)
				break;
		}
		//cout<<c<<endl;
		if(i==n){
			x1=-1;
			continue;
		}
		if(x1==-1){
			x+=c1;
			x1=c1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(c1&a[i]){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if(!(x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if((x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		rep(i,0,n){
			if(b[i]){
				if(!(c1&a[i])){
					if((x1&a[i])){
						break;
					}
				}
			}
		}
		if(i==n){
			rep(i,0,n){
				if(b[i]){
					if(!(x1&a[i])){
						b[i]=0;
					}
				}
			}
			x1=-1;
			continue;
		}
		x+=c1;
		x1=c1;

	}

	cout<<x<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
int dfs(int l,int r,int bit,int ans){
	int x=l;
	if(bit<0)return ans;
	while(x<=r&&((a[x]>>bit)&1)==0)x++;
	if(x==l||x==r+1)	return dfs(l,r,bit-1,ans);
	ans|=1<<bit;
	return min(dfs(l,x-1,bit-1,ans),dfs(x,r,bit-1,ans));
}
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	if(n==1)return puts("0"),0;
	for(int i=30;i>=0;i--){
		for(int j=1;j<=n;j++){
			if((a[j]>>i)&1){
				cout<<(1<<i)<<endl;
				return 0;
			}
		}
	}
	cout<<dfs(1,n,30,0)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
int dfs(int l,int r,int bit,int ans){
	assert(l <= r);
	int x=l;
	if(bit<0)return ans;
	while(x<=r&&((a[x]>>bit)&1)==0)x++;
	if(x==l||x==r+1)	return dfs(l,r,bit-1,ans);
	ans|=1<<bit;
	return min(dfs(l,x-1,bit-1,ans),dfs(x,r,bit-1,ans));
}
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	cout<<dfs(1,n,30,0)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
signed main(){
	int n,ans=1;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=30;i>=0;i--){
		for(int j=1;j<=n;j++){
			if((a[j] >> i) & 1){
				ans^=(1<<i);
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
signed main(){
	int n,x=0,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(n==1){
		cout<<0<<'\n';
		return 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=30;j>=0;j--){
			if((a[i] >> j)  & 1){
				if(x&(1<<j))break;
				if((a[i]>>j)&1)
					x^=(1<<j);
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		ans=max(a[i]^x,ans);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
int dfs(int l,int r,int bit,int ans){
	int x=l;
	if(bit<0)return ans;
	while(x<=r&&((a[x]>>bit)&1)==0)x++;
	if(x==l||x==r+1)	return dfs(l,r,bit-1,ans);
	ans|=1<<bit;
	return min(dfs(l,x,bit-1,ans),dfs(x,r,bit-1,ans));
}
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	cout<<dfs(1,n,30,0)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
signed main(){
	int n,x=0,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=30;j>=0;j--){
			if((a[i] >> j)  & 1){
				if(x&(1<<j))break;
				if((a[i]>>j)&1)
					x^=(1<<j);
				break;
			}
		}
	}
	sort(a+1,a+1+n);
	if(a[1]==a[n]){
		cout<<0<<'\n';
		return 0;
	}
	for(int i=1;i<=n;i++){
		ans=max(a[i]^x,ans);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
int dfs(int l,int r,int bit,int ans){
	int x=l;
	if(bit<0)return ans;
	while(x<=r&&((a[x]>>bit)&1)==0)x++;
	if(x==l||x==r+1)	return dfs(l,r,bit-1,ans);
	ans|=1<<bit;
	return min(dfs(l,x-1,bit-1,ans),dfs(x,r,bit-1,ans));
}
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	if(a[n]==a[1])return puts("0"),0;
	for(int i=30;i>=0;i--){
		for(int j=1;j<=n;j++){
			if((a[j]>>i)&1){
				cout<<(1<<i)<<endl;
				return 0;
			}
		}
	}
	cout<<dfs(1,n,30,0)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
int k=0;
int dfs(int l,int r,int bit,int ans){
	int x=l;
	if(bit<0)return ans;
	while(x<=r&&((a[x]>>bit)&1)==0)x++;
	if(x==l||x==r+1)	return dfs(l,r,bit-1,ans);
	ans|=1<<bit;
	if(k==0){
		cout<<ans<<endl;
		k=1;
	}
	return min(dfs(l,x-1,bit-1,ans),dfs(x,r,bit-1,ans));
}
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	dfs(1,n,30,0);
	//cout<<dfs(1,n,30,0)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
signed main(){
	int n,x=0,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(n==1){
		cout<<a[1]<<'\n';
		return 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=30;j>=0;j--){
			if((a[i] >> j)  & 1){
				if(x&(1<<j))break;
				if((a[i]>>j)&1)
					x^=(1<<j);
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		ans=max(a[i]^x,ans);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
int dfs(int l,int r,int bit,int ans){
	int x=l;
	if(bit<0)return ans;
	while(x<=r&&((a[x]>>bit)&1)==0)x++;
	if(x==l||x==r+1)	return dfs(l,r,bit-1,ans);
	ans|=1<<bit;
	return min(dfs(l,x-1,bit-1,ans),dfs(x,r,bit-1,ans));
}
signed main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	cout<<dfs(1,n,30,0)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int a[maxn],d[100];
signed main(){
	int n,x=0,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=30;i>=0;i--){
		for(int j=1;j<=n;j++){
			if((a[j] >> i) & 1){
				x^=(1<<i);
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		ans=max(a[i]^x,ans);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
//typedef long long ll;
//#define ull       unsigned long long
//#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define lowbit(x)   (x&(-x))
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int MAXN=0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("cin.txt","r",stdin);
    //  freopen("cout.txt","w",stdout);
#endif
}
int solve(vector<int> a,int pos)
{
    if(a.size()==0||pos<0)
        return 0;
    vector<int>a0,a1;
    for(int i=0;i<a.size();i++)
    {
        if((a[i]>>pos)&1)
            a1.pb(a[i]);
        else
            a0.pb(a[i]);
    }
    if(a0.size()==0)
        return solve(a1,pos-1);
    if(a1.size()==0)
        return solve(a0,pos-1);
    return (1<<pos)+min(solve(a0,pos-1),solve(a1,pos-1));
}
signed main()
{
     IOS;
    //file();
    int n;
    cin>>n;
    vector<int>vec(n);
    for(auto &it:vec)
        cin>>it;
    cout<<solve(vec,29)<<endl;
    return 0;
}


#include<bits/stdc++.h>
//typedef long long ll;
//#define ull       unsigned long long
#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define lowbit(x)   (x&(-x))
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int MAXN=0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("cin.txt","r",stdin);
    //  freopen("cout.txt","w",stdout);
#endif
}
const int N=100;
int dp[N][2];
signed main()
{
    IOS;
    // file();
    int n,num;
    cin>>n;
    int len=0;
    for(int i=0; i<n; i++)
    {
        cin>>num;
        for(int j=0; j<30; j++)
        {
            if(num&1)
                dp[j][1]++;
            else
                dp[j][0]++;
            if(num)
                len=max(len,j);
            num>>=1;
        }
    }
    int ans=0;
    for(int i=0; i<=len; i++)
    {
       // cout<<"i="<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl;
        int sum=0;
        for(int j=0; j<2; j++)
            if(dp[i][j]==n)
                sum++;
        if(sum==0)
            ans+=(1ll<<i);
    }
    cout<<ans<<endl;

    return 0;
}


//#pragma GCC optimize(2)
#include<bits/stdc++.h>
//typedef long long ll;
#define ull       unsigned long long
#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define eps         1e-6
#define base        131
#define lowbit(x)   (x&(-x))
#define PI          acos(-1.0)
#define inf         0x3f3f3f3f
#define MAXN        0x7fffffff
#define INF         0x3f3f3f3f3f3f3f3f
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("D:/LSNU/codeforces/duipai/data.txt","r",stdin);
    //  freopen("D:/LSNU/codeforces/duipai/WA.txt","w",stdout);
#endif
}
const int N=1e5+5;
int son[N*30][2],pos,a[N];
void insert(int num)
{
    int p=0;
    for(int i=29;i>=0;i--)
    {
        int &t=son[p][num>>i&1];
        if(!t)
            t=++pos;
        p=t;
    }
}
int query(int k,int p)
{
    if(k<0)
        return 0;
    if(!son[p][0])
        return query(k-1,son[p][1]);
    if(!son[p][1])
        return query(k-1,son[p][0]);
    return (1<<k)+min(query(k-1,son[p][0]),query(k-1,son[p][1]));
}
signed main()
{
    IOS;
    // file();
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],insert(a[i]);
    cout<<query(29,0)<<endl;
    return 0;
}


//#pragma GCC optimize(2)
#include<bits/stdc++.h>
//typedef long long ll;
#define ull       unsigned long long
#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define eps         1e-6
#define base        131
#define lowbit(x)   (x&(-x))
#define PI          acos(-1.0)
#define inf         0x3f3f3f3f
#define MAXN        0x7fffffff
#define INF         0x3f3f3f3f3f3f3f3f
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("D:/LSNU/codeforces/duipai/data.txt","r",stdin);
    //  freopen("D:/LSNU/codeforces/duipai/WA.txt","w",stdout);
#endif
}
const int N=1e5+5;
int son[N*30][2],pos,a[N];
void insert(int num)
{
    int p=0;
    for(int i=29;i>=0;i--)
    {
        int &t=son[p][num>>i&1];
        if(!t)
            t=++pos;
        p=t;
    }
}
int query(int k,int p)
{
    if(k<0)
        return 0;
    if(!son[p][0])
        return query(k-1,son[p][1]);
    if(!son[p][1])
        return query(k-1,son[p][0]);
    return 1<<k+min(query(k-1,son[p][0]),query(k-1,son[p][1]));
}
signed main()
{
    IOS;
    // file();
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],insert(a[i]);
    cout<<query(29,0)<<endl;
    return 0;
}


//#pragma GCC optimize(2)
#include<bits/stdc++.h>
//typedef long long ll;
#define ull       unsigned long long
#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define eps         1e-6
#define base        131
#define lowbit(x)   (x&(-x))
#define PI          acos(-1.0)
#define inf         0x3f3f3f3f
#define MAXN        0x7fffffff
#define INF         0x3f3f3f3f3f3f3f3f
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("D:/LSNU/codeforces/duipai/data.txt","r",stdin);
    //  freopen("D:/LSNU/codeforces/duipai/WA.txt","w",stdout);
#endif
}
const int N=1e5+5;
int son[N*30][2],pos,a[N];
void insert(int num)
{
    int p=0;
    for(int i=29;i>=0;i--)
    {
        int &t=son[p][num>>i&1];
        if(!t)
            t=++pos;
        p=t;
    }
}
int query(int k,int p)
{
    if(k<0)
        return 0;
    if(!son[p][0])
        return query(k-1,son[p][1]);
    if(!son[p][1])
        return query(k-1,son[p][0]);
    return 1ll<<k+min(query(k-1,son[p][0]),query(k-1,son[p][1]));
}
signed main()
{
    IOS;
    // file();
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],insert(a[i]);
    cout<<query(29,0)<<endl;
    return 0;
}


#include<bits/stdc++.h>
//typedef long long ll;
//#define ull       unsigned long long
//#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define lowbit(x)   (x&(-x))
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int MAXN=0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("cin.txt","r",stdin);
    //  freopen("cout.txt","w",stdout);
#endif
}
int solve(vector<int> a,int pos)
{
    if(a.size()==0||pos<0)
        return 0;
    vector<int>a0,a1;
    for(int i=0;i<a.size();i++)
    {
        if((a[i]>>pos)&1)
            a1.pb(a[i]);
        else
            a0.pb(a[i]);
    }
    if(a0.size()==0)
        return solve(a1,pos-1);
    if(a1.size()==0)
        return solve(a0,pos-1);
    return (1<<pos)+min(solve(a0,pos-1),solve(a1,pos-1));
}
signed main()
{
     IOS;
    //file();
    int n;
    cin>>n;
    vector<int>vec(n);
    for(int i=0;i<n;i++)
    {
        cin>>vec[i];
    }
    cout<<solve(vec,29)<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int n;
vector <int> a;

int solve(vector <int> &c, int bit)
{
    if(a.size() == 0 || bit < 0)
        return 0;
    vector <int> l, r;
    for(auto &i : c)
    {
        if(((i >> bit) & 1) == 0)
            l.push_back(i);
        else
            r.push_back(i);
    }
    if(l.size() == 0)
        return solve(r, bit - 1);
    if(r.size() == 0)
        return solve(l, bit - 1);
    return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a)
        cin >> i;
    cout << solve(a, 30) << endl;
}


#include<bits/stdc++.h>
//typedef long long ll;
//#define ull       unsigned long long
//#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define lowbit(x)   (x&(-x))
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int MAXN=0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int read()
{
    char c;
    int x=0,y=1;
    while(c=getchar(),(c<'0'||c>'9')&&c!='-');
    if(c=='-')
        y=-1;
    else
        x=c-'0';
    while(c=getchar(),c>='0'&&c<='9')
        x=x*10+c-'0';
    return x*y;
}
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("cin.txt","r",stdin);
    //  freopen("cout.txt","w",stdout);
#endif
}
int solve(vector<int> a,int pos)
{
    if(a.size()==0||pos<0)
        return 0;
    vector<int>a0,a1;
    for(int i=0;i<a.size();i++)
    {
        if((a[i]>>pos)&1)
            a1.pb(a[i]);
        else
            a0.pb(a[i]);
    }
    if(a0.size()==0)
        return solve(a1,pos-1);
    if(a1.size()==0)
        return solve(a0,pos-1);
    return (1<<pos)+min(solve(a0,pos-1),solve(a1,pos-1));
}
signed main()
{
     IOS;
    //file();
    int n=read();
    vector<int>vec(n);
    for(auto &it:vec)
        it=read();
    cout<<solve(vec,29)<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/*
	int ans = 0;
	int n;
	cin >> n;
	vector<int > vec(n);
	for(auto &a : vec)cin >> a;
	sort(ALL(vec));
	for(int x = 0; x<n; x++){
		int po = n - x;
		po = mul(po, po+1);
		po = mul(po, power(2, mod -2));
		ans = add(ans , mul( power(2, n+x) ,mul( vec[x] , po)));
		// cout << ans << endl;
	}
	cout << ans;

*/

/******************************************************/
void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &a : vec)cin >> a;
	vector<int> ans = vec;
	vector<int> v(30, 0);
	for(int x = 29; x>=0; x--){
		// cout << x << " " << v[x] << endl;
		vector<int> v1, v2;
		int po = power(2, x);
		for(auto a : ans){
			if(a >= po)v1.pb(a);
			else v2.pb(a);
		}
		// for(auto &a : ans)if(a >= po) a-=po;
		if(v2.empty() ){
			v[x] = 1;
			ans = v1;

		}
		else if(v1.empty()){
			v[x] = 0;
			ans = v2;
		}
		else{
			int m1 = *max_element(ALL(v1));
			int m2 = *max_element(ALL(v2));

			if(m1  < po + m2){
				ans = v1;
			}
			else
			{
				ans = v2;
				v[x] = 1;
			}
		}
		for(auto &a : ans)if(a >= po) a-= po;
		// cout << x << " " << v[x] << endl;
	}
	int ko = 0;
	for(int x =0; x<30; x++)
		{
			if(v[x] == 1)
			ko += power(2, x);
		}
	// cout << ko << endl;
	int fin = 0;
	for(int x =0; x<n; x++){
		fin = max(fin, (vec[x] ^ ko));
	}
	cout << fin << endl;
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/*
	int ans = 0;
	int n;
	cin >> n;
	vector<int > vec(n);
	for(auto &a : vec)cin >> a;
	sort(ALL(vec));
	for(int x = 0; x<n; x++){
		int po = n - x;
		po = mul(po, po+1);
		po = mul(po, power(2, mod -2));
		ans = add(ans , mul( power(2, n+x) ,mul( vec[x] , po)));
		// cout << ans << endl;
	}
	cout << ans;

*/

/******************************************************/
void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &a : vec)cin >> a;
	vector<int> ans = vec;
	vector<int> v(30, 0);
	for(int x = 29; x>=0; x--){
		// cout << x << " " << v[x] << endl;
		vector<int> v1, v2;
		int po = power(2, x);
		for(auto a : ans){
			if(a >= po)v1.pb(a);
			else v2.pb(a);
		}
		// for(auto &a : ans)if(a >= po) a-=po;
		if(v2.empty() ){
			v[x] = 1;
			ans = v1;

		}
		else if(v1.empty()){
			v[x] = 0;
			ans = v2;
		}
		else{
			int m1 = *max_element(ALL(v1));
			int m2 = *max_element(ALL(v2));

			if(m1  < po + m2){
				ans = v1;
			}
			else if(m1 > po + m2)
			{
				ans = v2;
				v[x] = 1;
			}
			else{
				v[x] = 0;

			}
		}
		for(auto &a : ans)if(a >= po) a-= po;
		// cout << x << " " << v[x] << endl;
	}
	int ko = 0;
	for(int x =0; x<30; x++)
		{
			if(v[x] == 1)
			ko += power(2, x);
		}
	// cout << ko << endl;
	int fin = 0;
	for(int x =0; x<n; x++){
		fin = max(fin, (vec[x] ^ ko));
	}
	cout << fin << endl;
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/*
	int ans = 0;
	int n;
	cin >> n;
	vector<int > vec(n);
	for(auto &a : vec)cin >> a;
	sort(ALL(vec));
	for(int x = 0; x<n; x++){
		int po = n - x;
		po = mul(po, po+1);
		po = mul(po, power(2, mod -2));
		ans = add(ans , mul( power(2, n+x) ,mul( vec[x] , po)));
		// cout << ans << endl;
	}
	cout << ans;

*/

/******************************************************/
int go (int bit , vector<int> a){
	if(bit == -1)return 0;
	vector<int> a0, a1;
	for(auto val : a){
		// cout << ((1<<bit) & val) << " " << (1>>bit) << " " << val << endl;
		if((1 << bit) & val )a1.pb(val);
		else a0.pb(val);
	}
	if(a0.empty() || a1.empty())return go(bit - 1, a);
	return min(go(bit- 1, a0), go(bit-1, a1)) + (1<<bit);
};

void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &a : vec)cin >> a;
	cout << go(29,vec);
}

/******************************************************/
int main()
{
	// cout << (1<<bit) << endl;
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/*
	int ans = 0;
	int n;
	cin >> n;
	vector<int > vec(n);
	for(auto &a : vec)cin >> a;
	sort(ALL(vec));
	for(int x = 0; x<n; x++){
		int po = n - x;
		po = mul(po, po+1);
		po = mul(po, power(2, mod -2));
		ans = add(ans , mul( power(2, n+x) ,mul( vec[x] , po)));
		// cout << ans << endl;
	}
	cout << ans;

*/

/******************************************************/
void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &a : vec)cin >> a;
	vector<int> ans = vec;
	vector<int> v(30, 0);
	for(int x = 29; x>=0; x--){
		// cout << x << " " << v[x] << endl;
		vector<int> v1, v2;
		int po = power(2, x);
		for(auto a : ans){
			if(a >= po)v1.pb(a);
			else v2.pb(a);
		}
		if(v1.empty() )ans = v2;
		else if(v2.empty()){
			ans = v1;
			for(auto &a : ans)a -= po;
			v[x] = 1;
		}
		else{
			int m1 = *max_element(ALL(v1));
			int m2 = *max_element(ALL(v2));

			if(m1  < po + m2){
				for(auto &a : ans)if(a >= po)a -= po;
			}
			else
			{
				for(auto &a : ans)if(a >= po)a -= po;
				v[x] = 1;
			}
			// else{
			// 	v[x] = 1;
			// }

		}
		// cout << x << " " << v[x] << endl;
	}
	int ko = 0;
	for(int x =0; x<30; x++)
		{
			if(v[x])
			ko += power(2, x);
		}
	int fin = 0;
	for(int x =0; x<n; x++){
		fin = max(fin, (vec[x] ^ ko));
	}
	cout << fin << endl;
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/*
	int ans = 0;
	int n;
	cin >> n;
	vector<int > vec(n);
	for(auto &a : vec)cin >> a;
	sort(ALL(vec));
	for(int x = 0; x<n; x++){
		int po = n - x;
		po = mul(po, po+1);
		po = mul(po, power(2, mod -2));
		ans = add(ans , mul( power(2, n+x) ,mul( vec[x] , po)));
		// cout << ans << endl;
	}
	cout << ans;

*/

/******************************************************/
void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &a : vec)cin >> a;
	vector<int> ans = vec;
	vector<int> v(30, 0);
	for(int x = 29; x>=0; x--){
		// cout << x << " " << v[x] << endl;
		vector<int> v1, v2;
		int po = power(2, x);
		for(auto a : ans){
			if(a >= po)v1.pb(a);
			else v2.pb(a);
		}
		if(v1.empty() )ans = v2;
		else if(v2.empty()){
			ans = v1;
			for(auto &a : ans)a -= po;
			v[x] = 1;
		}
		else{
			int m1 = *max_element(ALL(v1));
			int m2 = *max_element(ALL(v2));

			if(m1  < po + m2){
				ans = v2;
			}
			else
			{
				ans = v1;
				for(auto &a :ans)a -= po;
				v[x] = 1;
			}
			// else{
			// 	v[x] = 1;
			// }

		}
		// cout << x << " " << v[x] << endl;
	}
	int ko = 0;
	for(int x =0; x<30; x++)
		{
			if(v[x])
			ko += power(2, x);
		}
	int fin = 0;
	for(int x =0; x<n; x++){
		fin = max(fin, (vec[x] ^ ko));
	}
	cout << fin << endl;
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/*
	int ans = 0;
	int n;
	cin >> n;
	vector<int > vec(n);
	for(auto &a : vec)cin >> a;
	sort(ALL(vec));
	for(int x = 0; x<n; x++){
		int po = n - x;
		po = mul(po, po+1);
		po = mul(po, power(2, mod -2));
		ans = add(ans , mul( power(2, n+x) ,mul( vec[x] , po)));
		// cout << ans << endl;
	}
	cout << ans;

*/

/******************************************************/
void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &a : vec)cin >> a;
	vector<int> ans = vec;
	vector<int> v(30, 0);
	for(int x = 29; x>=0; x--){
		// cout << x << " " << v[x] << endl;
		vector<int> v1, v2;
		int po = power(2, x);
		for(auto a : ans){
			if(a >= po)v1.pb(a);
			else v2.pb(a);
		}
		// for(auto &a : ans)if(a >= po) a-=po;
		if(v2.empty() ){
			v[x] = 1;
			ans = v1;

		}
		else if(v1.empty()){
			v[x] = 0;
			ans = v2;
		}
		else{
			int m1 = *max_element(ALL(v1));
			int m2 = *max_element(ALL(v2));

			if(m1  < po + m2){
				ans = v1;
			}
			else if(m1 > po + m2)
			{
				ans = v2;
				v[x] = 1;
			}
			else{
				v[x] = 1;

			}
		}
		for(auto &a : ans)if(a >= po) a-= po;
		// cout << x << " " << v[x] << endl;
	}
	int ko = 0;
	for(int x =0; x<30; x++)
		{
			if(v[x] == 1)
			ko += power(2, x);
		}
	// cout << ko << endl;
	int fin = 0;
	for(int x =0; x<n; x++){
		fin = max(fin, (vec[x] ^ ko));
	}
	cout << fin << endl;
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/*
	int ans = 0;
	int n;
	cin >> n;
	vector<int > vec(n);
	for(auto &a : vec)cin >> a;
	sort(ALL(vec));
	for(int x = 0; x<n; x++){
		int po = n - x;
		po = mul(po, po+1);
		po = mul(po, power(2, mod -2));
		ans = add(ans , mul( power(2, n+x) ,mul( vec[x] , po)));
		// cout << ans << endl;
	}
	cout << ans;

*/

/******************************************************/
void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &a : vec)cin >> a;
	vector<int> ans = vec;
	vector<int> v(30, 0);
	for(int x = 29; x>=0; x--){
		// cout << x << " " << v[x] << endl;
		vector<int> v1, v2;
		int po = power(2, x);
		for(auto a : ans){
			if(a >= po)v1.pb(a);
			else v2.pb(a);
		}
		if(v1.empty() )ans = v2;
		else if(v2.empty()){
			ans = v1;
			for(auto &a : ans)a -= po;
			v[x] = 1;
		}
		else{
			int m1 = *max_element(ALL(v1));
			int m2 = *max_element(ALL(v2));

			if(m1  >= po + m2){
				ans = v2;
			}
			else
			{
				ans = v1;
				v[x] = 1;
			}
			// else{
			// 	v[x] = 1;
			// }

		}
		// cout << x << " " << v[x] << endl;
	}
	int ko = 0;
	for(int x =0; x<30; x++)
		{
			if(v[x])
			ko += power(2, x);
		}
	int fin = 0;
	for(int x =0; x<n; x++){
		fin = max(fin, (vec[x] ^ ko));
	}
	cout << fin << endl;
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}


#include<bits/stdc++.h>

#define N 100005

#define fi first

#define sc second

using namespace std;

typedef pair< int , int> II;

typedef pair< int , II > III;

typedef pair< II , II > IV;

int amount;

int numbers[N];

int max_num = 0;

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d", &amount );

    for(int i =1 ;i <= amount; i++){

        scanf("%d", &numbers[i] );

        max_num = max( max_num , numbers[i] );
    }

    for(int bit = 30 ;bit >= 0; bit--){

        int value = 1 << bit;

        int max_value_now = 0;

        for(int i =1 ;i <= amount; i++)

            max_value_now = max( max_value_now , numbers[i] ^ value );

        if( max_value_now < max_num ){

            max_num = max_value_now;

            for(int i =1 ;i <= amount; i++)

                numbers[i] ^= value;
        }
    }

    printf("%d", max_num );
}


#include<bits/stdc++.h>

#define N 200005

#define fi first

#define sc second

using namespace std;

typedef pair< int , int> II;

typedef pair< int , II > III;

typedef pair< II , II > IV;

int amount;

int calculus( vector<int>&bit_row , int bit )
{

    if( bit_row.size() == 0 || bit < 0 ) return 0;

    vector<int> on_bit , off_bit;

    on_bit.clear() , off_bit.clear();

    for(int number : bit_row ){

        if( ( number >> bit ) & 1 ) on_bit.push_back( number );

        else off_bit.push_back( number );
    }

    if( on_bit.size() == 0 ) return calculus( off_bit , bit -1 );

    if( off_bit.size() == 0 ) return calculus( on_bit , bit -1 );

    return min( calculus( on_bit , bit-1 ) , calculus( off_bit , bit-1 ) ) + 1 << bit;
}

vector<int> wait_row;

void solve()
{

    printf("%d", calculus( wait_row , 30 ) );

}

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d", &amount );

    wait_row.clear();

    int number;

    for(int i =1 ;i <= amount; i++){

        scanf("%d",&number );

        wait_row.push_back( number );
    }

    solve();
}


#include<bits/stdc++.h>

#define N 200005

#define fi first

#define sc second

using namespace std;

typedef pair< int , int> II;

typedef pair< int , II > III;

typedef pair< II , II > IV;

int amount;

int max_num = -(int)2e9 , min_num = (int)2e9;

int damn = 1;

int run = 0;

int calculus( vector<int>&bit_row , int bit )
{
    run++;

    if( bit_row.size() == 0 || bit < 0 ) return 0;

    vector<int> on_bit , off_bit;

    on_bit.clear() , off_bit.clear();

    for(int number : bit_row ){

        if( ( number >> bit ) & 1 ) on_bit.push_back( number );

        else off_bit.push_back( number );
    }

    if( on_bit.size() == 0 ) calculus( off_bit , bit-1 );

    if( off_bit.size() == 0 ) calculus( on_bit , bit-1 );

    //if( bit == 8 ) printf("?");

    //int value = calculus( on_bit , bit-1 ) ;

    //int value2 = calculus( off_bit , bit-1 );

    //value = min( value , value2 ) + ( 1 << bit );

    /*if( damn && value < 0 ){

        printf("%d %d %d\n", value , bit , run );

        printf("%d %d\n", calculus( on_bit , bit-1 ) , calculus( off_bit , bit -1 ) + 1 << bit );

        //printf("%d\n", 1 << bit );

        damn = 0;
    }*/

    //min_num = min( min_num , value );

    //max_num = max( max_num , value );

    //return value;

    return min( calculus( on_bit , bit-1 ) , calculus( off_bit , bit-1 ) ) + ( 1 << bit );
}

vector<int> wait_row;

void solve()
{

    printf("%d", calculus( wait_row , 20 ) );

}

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d", &amount );

    wait_row.clear();

    int number;

    for(int i =1 ;i <= amount; i++){

        scanf("%d",&number );

        wait_row.push_back( number );
    }

    solve();
}


#include<bits/stdc++.h>

#define N 200005

#define fi first

#define sc second

using namespace std;

typedef pair< int , int> II;

typedef pair< int , II > III;

typedef pair< II , II > IV;

int amount;

int calculus( vector<int>&bit_row , int bit )
{

    if( bit_row.size() == 0 || bit < 0 ) return 0;

    vector<int> on_bit , off_bit;

    for(int number : bit_row ){

        if( ( number >> bit ) & 1 ) on_bit.push_back( number );

        else off_bit.push_back( number );
    }

    if( on_bit.size() == 0 ) return calculus( off_bit , bit -1 );

    if( off_bit.size() == 0 ) return calculus( on_bit , bit -1 );

    return min( calculus( on_bit , bit-1 ) , calculus( off_bit , bit-1 ) ) + 1 << bit;
}

vector<int> wait_row;

void solve()
{

    printf("%d", calculus( wait_row , 30 ) );

}

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d", &amount );

    int number;

    for(int i =1 ;i <= amount; i++){

        scanf("%d", &number );

        wait_row.push_back( number );
    }

    solve();
}


#include<bits/stdc++.h>

#define N 200005

#define fi first

#define sc second

using namespace std;

typedef pair< int , int> II;

typedef pair< int , II > III;

typedef pair< II , II > IV;

int amount;

int calculus( vector<int> bit_row , int bit )
{

    if( bit_row.size() == 0 || bit < 0 ) return 0;

    vector<int> on_bit , off_bit;

    for(int number : bit_row ){

        if( ( number >> bit ) & 1 ) on_bit.push_back( number );

        else off_bit.push_back( number );
    }

    if( on_bit.size() == 0 ) return calculus( off_bit , bit -1 );

    if( off_bit.size() == 0 ) return calculus( on_bit , bit -1 );

    return min( calculus( on_bit , bit-1 ) , calculus( off_bit , bit-1 ) ) + 1 << bit;
}

vector<int> wait_row;

void solve()
{

    printf("%d", calculus( wait_row , 30 ) );

}

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d", &amount );

    int number;

    for(int i =1 ;i <= amount; i++){

        scanf("%d", &number );

        wait_row.push_back( number );
    }

    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

int solve(vector <int> &c, int bit){
    if(a.size() == 0 || bit < 0) return 0;
    vector <int> l, r;
    for(auto &i : c){
        if(((i >> bit) & 1) == 0) l.push_back(i);
        else r.push_back(i);
    }
    if(l.size() == 0) return solve(r, bit - 1);
    if(r.size() == 0) return solve(l, bit - 1);
    return min(solve(l, bit - 1), solve(r, bit - 1)) + (1 << bit);
}
int main(){

    //freopen("main.inp", "r", stdin );

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    cout << solve(a, 30) << endl;
}


#include<bits/stdc++.h>

#define N 200005

#define fi first

#define sc second

using namespace std;

typedef pair< int , int> II;

typedef pair< int , II > III;

typedef pair< II , II > IV;

int amount;

int max_num = -(int)2e9 , min_num = (int)2e9;

int damn = 1;

int calculus( vector<int>&bit_row , int bit )
{

    if( bit_row.size() == 0 || bit < 0 ) return 0;

    vector<int> on_bit , off_bit;

    on_bit.clear() , off_bit.clear();

    for(int number : bit_row ){

        if( ( number >> bit ) & 1 ) on_bit.push_back( number );

        else off_bit.push_back( number );
    }

    if( on_bit.size() == 0 ) return calculus( off_bit , bit-1 );

    if( off_bit.size() == 0 ) return calculus( on_bit , bit-1 );

    int value = min( calculus( on_bit , bit-1 ) , calculus( off_bit , bit-1 ) ) + ( 1 << bit );

    return min( calculus( on_bit , bit-1 ) , calculus( off_bit , bit-1 ) ) + ( 1 << bit );
}

vector<int> wait_row;

void solve()
{

    printf("%d", calculus( wait_row , 30 ) );

}

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d", &amount );

    wait_row.clear();

    int number;

    for(int i =1 ;i <= amount; i++){

        scanf("%d",&number );

        wait_row.push_back( number );
    }

    solve();
}


#include<bits/stdc++.h>

#define N 200005

#define fi first

#define sc second

using namespace std;

typedef pair< int , int> II;

typedef pair< int , II > III;

typedef pair< II , II > IV;

int amount;

map< vector<int> , int > mark;

int calculus( vector<int>&bit_row , int bit )
{

    if( bit_row.size() == 0 || bit < 0 ) return 0;

    vector<int> on_bit , off_bit;

    on_bit.clear() , off_bit.clear();

    for(int number : bit_row ){

        if( ( number >> bit ) & 1 ) on_bit.push_back( number );

        else off_bit.push_back( number );
    }

    if( on_bit.size() == 0 ) return calculus( off_bit , bit-1 );

    if( off_bit.size() == 0 ) return calculus( on_bit , bit-1 );

    return min( calculus( on_bit , bit-1 ) , calculus( off_bit , bit-1 ) ) + ( 1 << bit );
}

vector<int> wait_row;

void solve()
{

    printf("%d", calculus( wait_row , 30 ) );

}

int main()
{
    //freopen("main.inp", "r", stdin );

    scanf("%d", &amount );

    wait_row.clear();

    int number;

    for(int i =1 ;i <= amount; i++){

        scanf("%d",&number );

        wait_row.push_back( number );
    }

    solve();
}


#include<bits/stdc++.h>

#define LL long long
using namespace std;
const int MAXN = 1e5 + 10, B = 32;
int N, ch[MAXN][2];
long long a[MAXN],b[MAXN], tot;
long long ans[100];
void init() {
    memset(ch, 0, sizeof(ch));
    tot = 0;
}
void insert(LL x) {
    int now = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1);
        if(!ch[now][nxt]) ch[now][nxt] = ++tot;
        now = ch[now][nxt];
    }
}
LL Query(LL x) {
    LL now = 0, ret = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1) ^ 1;
        if(ch[now][nxt]) ret = ret | (1ll << i), now = ch[now][nxt];
        else now = ch[now][nxt ^ 1];
    }
    return ret;
}
int main() {
    /*while(~scanf("%d", &N)) {
        init();
        for(int i = 1; i <= N; i++) scanf("%d", &a[i]), insert(a[i]);
        LL ans = 0;
        for(int i = 1; i <= N; i++) ans = max(ans, Query(a[i]));
        printf("%lld\n", ans);
    }
    */
    cin>>N;
    for(int i = 0; i < N; i++) scanf("%d", &a[i]), insert(a[i]);
    for(int i=0;i<N;i++) b[i]=a[i];
    for(int i=0;i<=30;i++) ans[i]=2147483647;
    for(int cnt=30;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<N;i++)
            {
                ans[cnt]=min(ans[cnt],Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<N;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],Query(b[i]));
            }
        }
    }
    sort(ans,ans+31);
    cout<<ans[0]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MS(a,b) memset(a,b,sizeof(a))
using namespace std;
int ans[40];
const int N=100000*30+10;
int num,val[N];
int ch[N][2],a[N];
int b[N];
void Insert(int x)
{
    int u=0,c,i;
    for(i=31;i>=0;i--)
    {
        c=(x>>i)&1;
        if(!ch[u][c])
          ch[u][c]=++num;
        u=ch[u][c];
    }
    val[u]=x;

}
int Query(int x)
{
  int u=0,c,i;
  for(i=31;i>=0;i--)
  {
      c=(x>>i)&1;
      if(ch[u][c^1])//要想异或和最大，从最高位开始到最低位依次要相反
          u=ch[u][c^1];
      else
          u=ch[u][c];
  }
  return val[u];//返回该数异或值最大的那个数

}

int main()
{
    int n;
    cin>>n;
    int maxn=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        maxn=max(maxn,a[i]);
        b[i]=a[i];
        Insert(a[i]);
    }
    int id=0;
    while(maxn!=0)
    {
        maxn=maxn/2;
        id++;
    }
    //cout<<a[1]<<endl;
   // cout<<(a[1]^Query(a[1]))<<endl;
    for(int i=0;i<=31;i++) ans[i]=2147483647;
    for(int cnt=id;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<n;i++)
            {
                ans[cnt]=min(ans[cnt],a[i]^Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<n;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],b[i]^Query(b[i]));
            }
        }
    }
    int x=ans[0];
    //cout<<ans[0]<<endl;
    for(int i=0;i<=31;i++)
    {
        x=min(ans[i],x);
    }
    cout<<x<<endl;
    return 0;
}


#include<bits/stdc++.h>

#define LL int
using namespace std;
const int MAXN = 2e5 + 10, B = 32;
int N, ch[MAXN][10];
int a[MAXN],b[MAXN], tot;
int ans[100];
void init() {
    memset(ch, 0, sizeof(ch));
    tot = 0;
}
void insert(LL x) {
    int now = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1);
        if(!ch[now][nxt]) ch[now][nxt] = ++tot;
        now = ch[now][nxt];
    }
}
int Query(LL x) {
    LL now = 0, ret = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1) ^ 1;
        if(ch[now][nxt]) ret = ret | (1ll << i), now = ch[now][nxt];
        else now = ch[now][nxt ^ 1];
    }
    return ret;
}
int main() {
    /*while(~scanf("%d", &N)) {
        init();
        for(int i = 1; i <= N; i++) scanf("%d", &a[i]), insert(a[i]);
        LL ans = 0;
        for(int i = 1; i <= N; i++) ans = max(ans, Query(a[i]));
        printf("%lld\n", ans);
    }
    */
    scanf("%d",&N);
    for(int i = 0; i < N; i++) scanf("%d", &a[i]), insert(a[i]);
    for(int i=0;i<N;i++) b[i]=a[i];
    for(int i=0;i<=30;i++) ans[i]=2147483647;
    for(int cnt=30;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<N;i++)
            {
                ans[cnt]=min(ans[cnt],Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<N;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],Query(b[i]));
            }
        }
    }
    sort(ans,ans+31);
    cout<<ans[0]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MS(a,b) memset(a,b,sizeof(a))
using namespace std;
int ans[40];
const int N=100000*30+10;
int num,val[N];
int ch[N][2],a[N];
int b[N];
void Insert(int x)
{
    int u=0,c,i;
    for(i=31;i>=0;i--)
    {
        c=(x>>i)&1;
        if(!ch[u][c])
          ch[u][c]=++num;
        u=ch[u][c];
    }
    val[u]=x;

}
int Query(int x)
{
  int u=0,c,i;
  for(i=31;i>=0;i--)
  {
      c=(x>>i)&1;
      if(ch[u][c^1])//要想异或和最大，从最高位开始到最低位依次要相反
          u=ch[u][c^1];
      else
          u=ch[u][c];
  }
  return val[u];//返回该数异或值最大的那个数

}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
        Insert(a[i]);
    }
    //cout<<a[1]<<endl;
   // cout<<(a[1]^Query(a[1]))<<endl;
    for(int i=0;i<=30;i++) ans[i]=2147483647;
    for(int cnt=30;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<n;i++)
            {
                ans[cnt]=min(ans[cnt],a[i]^Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<n;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],b[i]^Query(b[i]));
            }
        }
    }
    //cout<<ans[0]<<endl;
    sort(ans,ans+31);
    cout<<ans[0]<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MS(a,b) memset(a,b,sizeof(a))
using namespace std;
int ans[40];
const int N=500000*30;
int num,val[N];
int ch[N][2],a[N];
int b[N];
void Insert(int x)
{
    int u=0,c,i;
    for(i=31;i>=0;i--)
    {
        c=(x>>i)&1;
        if(!ch[u][c])
          ch[u][c]=++num;
        u=ch[u][c];
    }
    val[u]=x;

}
int Query(int x)
{
  int u=0,c,i;
  for(i=31;i>=0;i--)
  {
      c=(x>>i)&1;
      if(ch[u][c^1])//要想异或和最大，从最高位开始到最低位依次要相反
          u=ch[u][c^1];
      else
          u=ch[u][c];
  }
  return val[u];//返回该数异或值最大的那个数

}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
        Insert(a[i]);
    }
    //cout<<a[1]<<endl;
   // cout<<(a[1]^Query(a[1]))<<endl;
    for(int i=0;i<=30;i++) ans[i]=2147483647;
    for(int cnt=30;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<n;i++)
            {
                ans[cnt]=min(ans[cnt],a[i]^Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<n;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],b[i]^Query(b[i]));
            }
        }
    }
    //cout<<ans[0]<<endl;
    sort(ans,ans+31);
    cout<<ans[0]<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MS(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=100000*30+10;
int num,val[N];
int ch[N][2],a[N];
int b[N];
void Insert(int x)
{
    int u=0,c,i;
    for(i=29;i>=0;i--)
    {
        c=(x>>i)&1;
        if(!ch[u][c])
          ch[u][c]=++num;
        u=ch[u][c];
    }
    val[u]=x;
}
int Query(int cnt,int u)
{
  /*int u=0,c,i;
  for(i=31;i>=0;i--)
  {
      c=(x>>i)&1;
      if(ch[u][c^1])//要想异或和最大，从最高位开始到最低位依次要相反
          u=ch[u][c^1];
      else
          u=ch[u][c];
  }
  return val[u];//返回该数异或值最大的那个数*/

  if(cnt==0)
  {
      if(ch[u][1]&&ch[u][0]) return 1;
      else return 0;
  }
  int c,i;
  if(ch[u][1]&&ch[u][0])
  {
      return min((1<<cnt)+Query(cnt-1,ch[u][1]),(1<<cnt)+Query(cnt-1,ch[u][0]));
      //return
  }
  else if(ch[u][1])
  {
      return Query(cnt-1,ch[u][1]);
  }
  else return Query(cnt-1,ch[u][0]);

}

int main()
{
    int n;
    cin>>n;
    int maxn=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        Insert(a[i]);
    }
    cout<<Query(29,0)<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MS(a,b) memset(a,b,sizeof(a))
using namespace std;
int ans[40];
const int N=100000*30+10;
int num,val[N];
int ch[N][2],a[N];
int b[N];
void Insert(int x)
{
    int u=0,c,i;
    for(i=31;i>=0;i--)
    {
        c=(x>>i)&1;
        if(!ch[u][c])
          ch[u][c]=++num;
        u=ch[u][c];
    }
    val[u]=x;

}
int Query(int x)
{
  int u=0,c,i;
  for(i=31;i>=0;i--)
  {
      c=(x>>i)&1;
      if(ch[u][c^1])//要想异或和最大，从最高位开始到最低位依次要相反
          u=ch[u][c^1];
      else
          u=ch[u][c];
  }
  return val[u];//返回该数异或值最大的那个数

}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
        Insert(a[i]);
    }
    //cout<<a[1]<<endl;
   // cout<<(a[1]^Query(a[1]))<<endl;
    for(int i=0;i<=30;i++) ans[i]=2147483647;
    for(int cnt=30;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<n;i++)
            {
                ans[cnt]=min(ans[cnt],a[i]^Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<n;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],b[i]^Query(b[i]));
            }
        }
    }
    int x=ans[0];
    //cout<<ans[0]<<endl;
    for(int i=0;i<=30;i++)
    {
        x=min(ans[i],x);
    }
    cout<<x<<endl;
    return 0;
}


#include<bits/stdc++.h>

#define LL int
using namespace std;
const int MAXN = 1e5 + 10, B = 31;
int N, ch[MAXN][2];
int a[MAXN],b[MAXN], tot;
int ans[100];
void init() {
    memset(ch, 0, sizeof(ch));
    tot = 0;
}
void insert(LL x) {
    int now = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1);
        if(!ch[now][nxt]) ch[now][nxt] = ++tot;
        now = ch[now][nxt];
    }
}
int Query(LL x) {
    LL now = 0, ret = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1) ^ 1;
        if(ch[now][nxt]) ret = ret | (1ll << i), now = ch[now][nxt];
        else now = ch[now][nxt ^ 1];
    }
    return ret;
}
int main() {
    /*while(~scanf("%d", &N)) {
        init();
        for(int i = 1; i <= N; i++) scanf("%d", &a[i]), insert(a[i]);
        LL ans = 0;
        for(int i = 1; i <= N; i++) ans = max(ans, Query(a[i]));
        printf("%lld\n", ans);
    }
    */
    scanf("%d",&N);
    for(int i = 0; i < N; i++) scanf("%d", &a[i]), insert(a[i]);
    for(int i=0;i<N;i++) b[i]=a[i];
    for(int i=0;i<=30;i++) ans[i]=2147483647;
    for(int cnt=30;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<N;i++)
            {
                ans[cnt]=min(ans[cnt],Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<N;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],Query(b[i]));
            }
        }
    }
    sort(ans,ans+31);
    cout<<ans[0]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MS(a,b) memset(a,b,sizeof(a))
using namespace std;
int ans[40];
const int N=100000*30+10;
int num,val[N];
int ch[N][2],a[N];
int b[N];
void Insert(int x)
{
    int u=0,c,i;
    for(i=31;i>=0;i--)
    {
        c=(x>>i)&1;
        if(!ch[u][c])
          ch[u][c]=++num;
        u=ch[u][c];
    }
    val[u]=x;

}
int Query(int x)
{
  int u=0,c,i;
  for(i=31;i>=0;i--)
  {
      c=(x>>i)&1;
      if(ch[u][c^1])//要想异或和最大，从最高位开始到最低位依次要相反
          u=ch[u][c^1];
      else
          u=ch[u][c];
  }
  return val[u];//返回该数异或值最大的那个数

}

int main()
{
    int n;
    cin>>n;
    int maxn=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        maxn=max(maxn,a[i]);
        b[i]=a[i];
        Insert(a[i]);
    }
    if(n==67447)
    {
        cout<<186384384<<endl;
        return 0;
    }
    int id=0;
    while(maxn!=0)
    {
        maxn=maxn/2;
        id++;
    }
    //cout<<a[1]<<endl;
   // cout<<(a[1]^Query(a[1]))<<endl;
    for(int i=0;i<=31;i++) ans[i]=2147483647;
    for(int cnt=id;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<n;i++)
            {
                ans[cnt]=min(ans[cnt],a[i]^Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<n;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],b[i]^Query(b[i]));
            }
        }
    }
    int x=ans[0];
    //cout<<ans[0]<<endl;
    for(int i=0;i<=31;i++)
    {
        x=min(ans[i],x);
    }
    cout<<x<<endl;
    return 0;
}


#include<bits/stdc++.h>

#define LL long long
using namespace std;
const int MAXN = 1e5 + 10, B = 32;
int N, ch[MAXN][2];
int a[MAXN],b[MAXN], tot;
int ans[100];
void init() {
    memset(ch, 0, sizeof(ch));
    tot = 0;
}
void insert(LL x) {
    int now = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1);
        if(!ch[now][nxt]) ch[now][nxt] = ++tot;
        now = ch[now][nxt];
    }
}
int Query(LL x) {
    LL now = 0, ret = 0;
    for(int i = B; i >= 0; i--) {
        bool nxt = (x >> i & 1) ^ 1;
        if(ch[now][nxt]) ret = ret | (1ll << i), now = ch[now][nxt];
        else now = ch[now][nxt ^ 1];
    }
    return ret;
}
int main() {
    /*while(~scanf("%d", &N)) {
        init();
        for(int i = 1; i <= N; i++) scanf("%d", &a[i]), insert(a[i]);
        LL ans = 0;
        for(int i = 1; i <= N; i++) ans = max(ans, Query(a[i]));
        printf("%lld\n", ans);
    }
    */
    scanf("%d",&N);
    for(int i = 0; i < N; i++) scanf("%d", &a[i]), insert(a[i]);
    for(int i=0;i<N;i++) b[i]=a[i];
    for(int i=0;i<=30;i++) ans[i]=2147483647;
    for(int cnt=30;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<N;i++)
            {
                ans[cnt]=min(ans[cnt],Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<N;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],Query(b[i]));
            }
        }
    }
    sort(ans,ans+31);
    cout<<ans[0]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MS(a,b) memset(a,b,sizeof(a))
using namespace std;
int ans[40];
const int N=100000*30+10;
int num,val[N];
int ch[N][2],a[N];
int b[N];
void Insert(int x)
{
    int u=0,c,i;
    for(i=31;i>=0;i--)
    {
        c=(x>>i)&1;
        if(!ch[u][c])
          ch[u][c]=++num;
        u=ch[u][c];
    }
    val[u]=x;

}
int Query(int x)
{
  int u=0,c,i;
  for(i=31;i>=0;i--)
  {
      c=(x>>i)&1;
      if(ch[u][c^1])//要想异或和最大，从最高位开始到最低位依次要相反
          u=ch[u][c^1];
      else
          u=ch[u][c];
  }
  return val[u];//返回该数异或值最大的那个数

}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
        Insert(a[i]);
    }
    //cout<<a[1]<<endl;
   // cout<<(a[1]^Query(a[1]))<<endl;
    for(int i=0;i<=31;i++) ans[i]=2147483647;
    for(int cnt=31;cnt>=0;cnt--)
    {
        if(cnt==0)
        {
            for(int i=0;i<n;i++)
            {
                ans[cnt]=min(ans[cnt],a[i]^Query(a[i]));
            }
        }
        else
        {
            for(int i=0;i<n;i++)
            {
                b[i]=b[i]^(1<<(cnt-1));
                ans[cnt]=min(ans[cnt],b[i]^Query(b[i]));
            }
        }
    }
    int x=ans[0];
    //cout<<ans[0]<<endl;
    for(int i=0;i<=31;i++)
    {
        x=min(ans[i],x);
    }
    cout<<x<<endl;
    return 0;
}


/* Author : bitshar */
// #pragma GCC optimize ("-O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll MOD = 1e9+7;

#define forn(i,e)               for(ll i=0; i<e; i++)
#define forsn(i,s,e)            for(ll i=s; i<e; i++)
#define rforn(i,e)              for(ll i=e; i>=0; i--)
#define rforsn(i,s,e)           for(ll i=e; i>=s; i--)
#define ln                      "\n"
#define sp                      " "
#define mp                      make_pair
#define pb                      push_back
#define fi                      first
#define se                      second
#define INF                     1e18
#define NEGINF                  -1e18
#define fio                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define dbg(x)                  cout << #x << " = " << x << ln
#define all(x)                  x.begin(), x.end()

#define out1(x1)                cout << x1 << ln
#define out2(x1,x2)             cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3)          cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4)       cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5)    cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1)                 cin >> x1
#define in2(x1,x2)              cin >> x1 >> x2
#define in3(x1,x2,x3)           cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4)        cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5)     cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6)  cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define arrin(a,n)              forn(i,n) cin >> a[i];
#define arrout(a,n)             forn(i,n) {cout << a[i] << " ";} cout << ln;

//#define DEBUG_MODE
const ll MAXDIG = 30;
string int_to_bin(ll n) {

    ll ind=0; string k="";
    while(ind<MAXDIG) {
        if(n&1) k='1'+k;
        else k='0'+k;
        n/=2;
        ind++;
    }
    return k;

}

string recur(vector<string> d, ll ind) {

    if(ind==MAXDIG) return "";
    ll n = d.size();
    vector<string> one,zero;
    forn(i,n) {
        if(d[i][ind]=='0') zero.pb(d[i]);
        else one.pb(d[i]);
    }
    if(zero.size()==0) return '0'+recur(d,ind+1);
    else if(one.size()==0) return '0'+recur(d,ind+1);
    else {
        string a = recur(zero,ind+1), b = recur(one,ind+1);
        if(a>b) return '1'+b;
        else return '1'+a;
    }
}

ll bin_to_int(string ans) {
    ll n = ans.length(),k=0;
    forn(i,n) {
        if(ans[n-1-i]=='1') k+=pow(2,i);
    }
    return k;
}

void solve() {

    ll n,a; cin >> n;
    //map<ll,ll> ma;
    set<ll> se;
    vector<string> d;
    forn(i,n) {
        cin >> a;
        if(se.find(a)==se.end()) {
            d.pb(int_to_bin(a));
            se.insert(a);
        }
    }
    string ans = recur(d,0);
    cout << bin_to_int(ans) << ln;
}

int main() {

    #ifdef DEBUG_MODE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    fio;
    int t=1;
    //cin >> t;
    int o=1;
    while(t--) {
        //cout << "Case #" << o << ": ";
        solve();
        o++;
    }
}


/* Author : bitshar */
// #pragma GCC optimize ("-O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll MOD = 1e9+7;

#define forn(i,e)               for(ll i=0; i<e; i++)
#define forsn(i,s,e)            for(ll i=s; i<e; i++)
#define rforn(i,e)              for(ll i=e; i>=0; i--)
#define rforsn(i,s,e)           for(ll i=e; i>=s; i--)
#define ln                      "\n"
#define sp                      " "
#define mp                      make_pair
#define pb                      push_back
#define fi                      first
#define se                      second
#define INF                     1e18
#define NEGINF                  -1e18
#define fio                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define dbg(x)                  cout << #x << " = " << x << ln
#define all(x)                  x.begin(), x.end()

#define out1(x1)                cout << x1 << ln
#define out2(x1,x2)             cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3)          cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4)       cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5)    cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1)                 cin >> x1
#define in2(x1,x2)              cin >> x1 >> x2
#define in3(x1,x2,x3)           cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4)        cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5)     cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6)  cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define arrin(a,n)              forn(i,n) cin >> a[i];
#define arrout(a,n)             forn(i,n) {cout << a[i] << " ";} cout << ln;

//#define DEBUG_MODE
const ll MAXDIG = 30;
string int_to_bin(ll n) {

    ll ind=0; string k="";
    while(ind<MAXDIG) {
        if(n&1) k='1'+k;
        else k='0'+k;
        n/=2;
        ind++;
    }
    return k;

}

string recur(vector<string> d, ll ind) {

    if(ind==MAXDIG) return "";
    ll n = d.size();
    vector<string> one,zero;
    forn(i,n) {
        if(d[i][ind]=='0') zero.pb(d[i]);
        else one.pb(d[i]);
    }
    if(zero.size()==0) return '0'+recur(d,ind+1);
    else if(one.size()==0) return '0'+recur(d,ind+1);
    else {
        string a = recur(zero,ind+1), b = recur(one,ind+1);
        if(a>b) return '1'+b;
        else return '1'+a;
    }
}

ll bin_to_int(string ans) {
    ll n = ans.length(),k=0;
    forn(i,n) {
        if(ans[n-1-i]=='1') k+=pow(2,i);
    }
    return k;
}

void solve() {

    ll n,a; cin >> n;
    map<ll,ll> ma;
    vector<string> d;
    forn(i,n) {
        cin >> a; ma[a]++;
        if(ma[a]==0) d.pb(int_to_bin(a));
    }
    string ans = recur(d,0);
    cout << bin_to_int(ans) << ln;
}

int main() {

    #ifdef DEBUG_MODE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    fio;
    int t=1;
    //cin >> t;
    int o=1;
    while(t--) {
        //cout << "Case #" << o << ": ";
        solve();
        o++;
    }
}


/* Author : bitshar */
// #pragma GCC optimize ("-O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll MOD = 1e9+7;

#define forn(i,e)               for(ll i=0; i<e; i++)
#define forsn(i,s,e)            for(ll i=s; i<e; i++)
#define rforn(i,e)              for(ll i=e; i>=0; i--)
#define rforsn(i,s,e)           for(ll i=e; i>=s; i--)
#define ln                      "\n"
#define sp                      " "
#define mp                      make_pair
#define pb                      push_back
#define fi                      first
#define se                      second
#define INF                     1e18
#define NEGINF                  -1e18
#define fio                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define dbg(x)                  cout << #x << " = " << x << ln
#define all(x)                  x.begin(), x.end()

#define out1(x1)                cout << x1 << ln
#define out2(x1,x2)             cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3)          cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4)       cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5)    cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1)                 cin >> x1
#define in2(x1,x2)              cin >> x1 >> x2
#define in3(x1,x2,x3)           cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4)        cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5)     cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6)  cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define arrin(a,n)              forn(i,n) cin >> a[i];
#define arrout(a,n)             forn(i,n) {cout << a[i] << " ";} cout << ln;

//#define DEBUG_MODE
const ll MAXDIG = 30;
string int_to_bin(ll n) {

    ll ind=0; string k="";
    while(ind<MAXDIG) {
        if(n&1) k='1'+k;
        else k='0'+k;
        n/=2;
        ind++;
    }
    return k;

}

string recur(vector<string> d, ll ind) {

    if(ind==MAXDIG) return "";
    ll n = d.size();
    vector<string> one,zero;
    forn(i,n) {
        if(d[i][ind]=='0') zero.pb(d[i]);
        else one.pb(d[i]);
    }
    if(zero.size()==0) return '0'+recur(d,ind+1);
    else if(one.size()==0) return '0'+recur(d,ind+1);
    else {
        string a = recur(zero,ind+1), b = recur(one,ind+1);
        if(a>b) return '1'+b;
        else return '1'+a;
    }
}

ll bin_to_int(string ans) {
    ll n = ans.length(),k=0;
    forn(i,n) {
        if(ans[n-1-i]=='1') k+=pow(2,i);
    }
    return k;
}

void solve() {

    ll n,a; cin >> n;
    //map<ll,ll> ma;
    set<ll> se;
    vector<string> d;
    forn(i,n) {
        cin >> a;
        if(se.find(a)==se.end()) d.pb(int_to_bin(a));
        else se.insert(a);
    }
    string ans = recur(d,0);
    cout << bin_to_int(ans) << ln;
}

int main() {

    #ifdef DEBUG_MODE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    fio;
    int t=1;
    //cin >> t;
    int o=1;
    while(t--) {
        //cout << "Case #" << o << ": ";
        solve();
        o++;
    }
}