#include <bits/stdc++.h>

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

ll probaj(int bit)
{
    for(int j = 0; j < MAXBIT; j++)cntt[j]=cnt[j];
    ll ret = 0LL;
    bool ok=false;
    for(int i = 0; i < n; i++)
    {
        if(a[i]&(1LL<<bit))continue;
        cntt[bit]^=1;
        ll levo = 0LL;
        ll desno = 0LL;
        for(int j = 0; j < bit; j++)if(a[i]&(1LL<<j))levo+=(1LL<<j);
        for(int j = bit+1; j < MAXBIT; j++)if(a[i]&(1LL<<j)){desno=(1LL<<j);break;}
        ll add = (1LL<<bit);
        ll v1 = abs((1LL<<bit)-levo);
        ll v2 = abs((1LL<<bit)-desno);
        add=min(add,v1);
        add=min(add,v2);
        ret += add;
        if(v1==v2&&levo!=0&&desno!=0)ok=true;
        if(v1==add&&levo!=0)
        {
            for(int j = 0; j < bit; j++)
            {
                if(a[i]&(1LL<<j))cntt[j]^=1;
            }
        }
        else if(v2==add&&desno!=0)
        {
            for(int j = bit+1; j < MAXBIT; j++)
            {
                if(a[i]&(1LL<<j)){cntt[j]^=1;break;}
            }
        }
    }
    for(int j = 0; j < MAXBIT; j++)
    {
        if(cntt[j]==1)ok=true;
    }
    if(ok)return ret;
    return ret+1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    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]^=1;
        }
    }
    ll ans = INF;
    for(int j = 0; j < MAXBIT; j++)
    {
        ans=min(ans,probaj(j));
    }
    cout << ans;
    return 0;
}