#include <bits/stdc++.h>

using namespace std;
#define MAXN 500005
#define MAXBIT 63
typedef long long ll;
ll a[MAXN];
int cnt[MAXBIT];
int cntt[MAXBIT];
const ll LIMIT = 1e16;
ll sumalevo[MAXN][MAXBIT];
int prvidesno[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]^=1;
                sumalevo[i][j]=(1LL<<j);
            }
            if(j>0)sumalevo[i][j]+=sumalevo[i][j-1];
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = MAXBIT-1; j >= 0; j--)
        {
            if(a[i]&(1LL<<j))
            {
                prvidesno[i][j]=j;
            }
            else prvidesno[i][j]=prvidesno[i][j+1];
        }
    }
    ll ans = 1e18;
    for(int j = 0; j < MAXBIT; j++)
    {
        for(int k = 0; k < MAXBIT; k++)cntt[k]=cnt[k];
        ll s=0LL;
        bool moze = false;
        for(int i = 0; i < n; i++)
        {
            if(a[i]&(1LL<<j))continue;
            ll add=(1LL<<j);
            ll levo=sumalevo[i][j-1];
            ll desno=0LL;
            if(prvidesno[i][j+1]!=0)desno=(1LL<<prvidesno[i][j+1]);
            add=min(add,abs((1LL<<j)-levo));
            add=min(add,abs((1LL<<j)-desno));
            if(levo!=0&&desno!=0 && abs((1LL<<j)-levo)==abs((1LL<<j)-desno))moze=true;
            s+=add;
            if(s > LIMIT)break;
            cntt[j]^=1;
            if(levo != 0 && abs((1LL<<j)-levo)==add)
            {
                for(int k = 0; k < j; k++)
                {
                    if(a[i]&(1LL<<k))cntt[k]^=1;
                }
            }
            else if(desno != 0 && abs((1LL<<j)-desno)==add)
            {
                cntt[prvidesno[i][j+1]]^=1;
            }
        }
        for(int k = 0; k < MAXBIT; k++)
        {
            if(cntt[k]==1){moze=true;break;}
        }
        if(!moze)
        {
            if(j!=0)ans=min(ans,s+1);
            else ans=min(ans,s+2);
        }
        else ans=min(ans,s);
    }
    cout << ans;
    return 0;
}