#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) x.first(),x.second()
#define MAXN 500005

typedef long long ll;
using namespace std;
ll n;
ll niz[MAXN];
ll maska;
ll tniz[MAXN];
ll tres,txor,res=LLONG_MAX,nmax;

int main(){ /// PROMENI U LONG LONG SVE
    scanf("%lld", &n);
    for(ll i=1ll;i<=n;i++){
        scanf("%lld",niz+i);
        nmax=max(nmax,niz[i]);
    }
    for(ll j=0;j<62ll;j++){

        tres=0ll;txor=0ll;
        maska|=(1ll<<j);

        for(ll i=1ll;i<=n;i++){
            if(tres>res)goto kraj;
            ll ostatak=(niz[i]&maska);
            if(ostatak<(1ll<<j)){


                if(niz[i]==ostatak){
                    tniz[i]=(1ll<<j);
                    tres+=(tniz[i]-niz[i]);
                }else{
                    if(ostatak+1ll<(1ll<<j)-ostatak){
                        tniz[i]=(niz[i]-ostatak-1ll);
                        tres+=ostatak+1ll;
                    }else{
                        tniz[i]=niz[i]-ostatak+(1ll<<j);
                        tres+=-ostatak+(1ll<<j);
                    }
                }

            }else
                tniz[i]=niz[i];

            txor ^= tniz[i];

        }

        if(txor==0){
            if(j==0 && nmax<=1){
                tres++;
            }
            tres++;
        }
        //printf("%lld %lld\n",tres,res);
        res=min(res,tres);
        kraj:continue;
    }

    printf("%lld",res);
    return 0;
}