#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct edge{
int qs;
int zz;
int w;
}E[4000001];
int a[2001];
int f[2001];
int n,k=0,m=0;
long long sum=0;
bool cmp(const edge &a,const edge &b){
return a.w>b.w;
}
int get(int x){
if (f[x]!=x) f[x]=get(f[x]);
return f[x];
}
int main()
{
freopen("superbull.in","r",stdin);
freopen("superbull.out","w",stdout);
cin>>n;
for (int i=1;i<=n;++i)
scanf("%d",&a[i]);
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
if (i!=j)
{
m++;
E[m].qs=i;
E[m].zz=j;
E[m].w=a[i]^a[j];
}
sort(E+1,E+1+m,cmp);
for (int i=1;i<=n;++i)
f[i]=i;
for (int i=1;i<=m;++i)
{
int p=get(E[i].qs);
int q=get(E[i].zz);
if (p!=q)
{
f[p]=q;
sum+=E[i].w;
k++;
}
if (k==n-1)
{
cout<<sum;
return 0;
}
}
}