#include <bits/stdc++.h>

using namespace std;
#define MAXN 500005
#define MAXBIT 50
typedef long long ll;
ll a[MAXN];
int cnt[MAXN];
const ll INF = 1e18;
ll levo[MAXN][MAXBIT];
ll desno[MAXN][MAXBIT];

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        for(int j = 0; j < MAXBIT; j++)
        {
            if(a[i]&&(1LL<<j))
            {
                cnt[j]++;
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        ll tr = INF;
        for(int j = 0; j < MAXBIT; j++)
        {
            if(a[i]&(1LL<<j))
            {
                tr=(1LL<<j);
            }
            levo[i][j]=tr;
        }
    }
    for(int i = 0; i < n; i++)
    {
        ll tr = INF;
        for(int j = MAXBIT-1; j >= 0; j--)
        {
            if(a[i]&(1LL<<j))
            {
                tr=(1LL<<j);
            }
            desno[i][j]=tr;
        }
    }
    ll ans = INF;
    for(int j = 0; j < MAXBIT; j++)
    {
        ll tr = 0;
        //ovo je za AND
        ll mini = INF;
        for(int i = 0; i < n; i++)
        {
            if(!(a[i]&&(1<<j)))
            {
                tr += 1LL<<j;
                mini=min(abs(levo[i][j]-(1LL<<j),abs(desno[i][j]-(1LL<<j))));
            }
        }
        if(n%2==0)
        {
            ll vv = tr;
            vv += mini;
            vv -= (1LL<<j);
            tr=vv;
        }
        ans=min(ans,tr);
    }
    cout << ans;
    return 0;
}