#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define f first
#define s second

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> drvo; ///find_by_order()  order_of_key()

int L=60;
int main()
{
    int n;
    scanf("%i",&n);
    vector<ll> niz(n);
    for(int i=0;i<n;i++)
        scanf("%lld",&niz[i]);
    ll best=LLONG_MAX;
    for(int j=1;j<L;j++)
    {
        ll bit=1LL<<j;
        ll price=0;
        ll xorr=0;
        bool izbor=false;
        for(int i=0;i<n;i++)
        {
            if(niz[i]&bit){
                xorr^=niz[i];
                continue;
            }
            ll cenagore=1,cenadole=1;
            ll trbit=bit>>1;
            ll gore=niz[i],dole=niz[i];
            while(trbit)
            {
                if(niz[i]&trbit)
                    cenadole+=trbit,dole-=trbit;
                else
                    cenagore+=trbit,gore+=trbit;
                trbit>>=1;
            }
            if(niz[i]<bit)
                cenadole=LLONG_MAX;
            if(cenagore==cenadole)
            {
                izbor=true;
                price+=cenadole;
            }
            gore++;
            dole--;
            if(cenagore<cenadole)
            {
                xorr^=gore;
                price+=cenagore;
            }
            if(cenagore>cenadole)
            {
                xorr^=dole;
                price+=cenadole;
            }
        }
        if(xorr==0&&izbor==false)
            price++;
        best=min(best,price);
    }
    ll pricee=0;
    ll xorre=0;
    bool izbor=false;
    for(int i=0;i<n;i++)
    {
        if((niz[i]&1)==0){
            if(niz[i]>0)
                izbor=true;
            pricee++;
        }
        xorre^=(niz[i]|1);
    }
    if(xorre==0&&izbor==false)
        pricee+=2;
    best=min(best,pricee);
    printf("%lld\n",best);
    return 0;
}