#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define int long long
#define endl '\n'
const int maxn = 2e5 + 5;
const int maxm = maxn * 40;
int n,a[maxn];
int rt[maxm][2],L[maxm],R[maxm],idx,root;
void insert(int &now,int dep,int x){
if (!now) now = ++idx;
L[now] = min(L[now],x),R[now] = max(R[now],x);
if (dep < 0 ) return;
insert(rt[now][a[x] >> dep & 1],dep - 1,x);
}
int query(int now,int x,int dep){
if (dep < 0) return 0;
int bit = x >> dep & 1;
if (rt[now][bit]) return query(rt[now][bit],x,dep - 1);
return query(rt[now][bit ^ 1],x,dep - 1) + (1 << dep);
}
int dfs(int now,int dep){
if (dep < 0) return 0;
if (R[rt[now][0]] && R[rt[now][1]]){
int minn = 5e9;
for (int i = L[rt[now][0]]; i <= R[rt[now][0]]; ++i) {
minn = min(minn, query(rt[now][1],a[i],dep - 1));
}
return minn + dfs(rt[now][0],dep - 1) + dfs(rt[now][1],dep - 1) + (1 << dep);
}
if (R[rt[now][0]]) return dfs(rt[now][0],dep - 1);
if (R[rt[now][1]]) return dfs(rt[now][1],dep - 1);
return 0;
}
void solve(){
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(a + 1,a + 1 + n);
memset(L,0x3f,sizeof L);
for (int i = 1; i <= n; ++i) {
insert(root,30,i);
}
cout << dfs(root,30);
}
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
// cin >> t;
while (t--) solve();
}