#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 4e6 + 10;
struct node {
int x, y, w;
}
e[2 * MAXN];
int n;
int e_cnt;
int d[2000000];
int E[1500000];
bool v[2000000];
int f[1500000];
int find(int x) {
return x == f[x] ? x : (f[x] = find(f[x]));
}
void join(int x, int y) {
f[find(x)] = find(y);
}
void add(int x, int y, int w) {
e[++e_cnt].x = x;
e[e_cnt].y = y;
e[e_cnt].w = w;
}
signed main() {
int a[MAXN];
cin >> n;
for(int i = 1; i <= n; i++) {
f[i] = i;
cin >> a[i];
for(int j = 1; j < i; j++) {
add(j, i, (a[i] ^ a[j]));
add(i, j, (a[i] ^ a[j]));
}
}
int tot = 0;
while (true) {
int cur = 0;
for(int i = 1; i <= n; i++) {
d[i] = 1e9;
}
for(int i = 1; i <= e_cnt; i++) {
int a = find(e[i].x), b = find(e[i].y), c = e[i].w;
if(a == b) continue;
cur++;
if(c < d[a] || c == d[a] && i < E[a]) d[a] = c, E[a] = i;
if(c < d[b] || c == d[b] && i < E[b]) d[b] = c, E[b] = i;
}
if(cur == 0)
break;
for(int i = 1; i <= n; i++)
if(d[i] != 1e9 && !v[E[i]]) {
join(e[E[i]].x, e[E[i]].y), tot += e[E[i]].w;
v[E[i]] = true;
}
}
cout<<tot;
return 0;
}