#include<bits/stdc++.h>

using namespace std;

int n;
vector<unsigned long long> brojevi;
unsigned long long xorovan;
unsigned long long andovan;
unsigned long long power;
bool da=true;
unsigned long long minres;
unsigned long long trenres;
unsigned long long minpower;
int minpoz;
bool uf;
int ej;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;

    brojevi.resize(n);
    for(int i=0;i<n;i++)
        cin >> brojevi[i];
    xorovan=brojevi[0];
    andovan=brojevi[0];
    for(int i=1;i<n;i++)
        xorovan^=brojevi[i],andovan&=brojevi[i];
    if(xorovan > 0 && andovan >0)
        cout << "0" << endl;
    else if(xorovan == 0 && andovan>0)
    {
        if(andovan==1)
            cout << "2" << endl;
        else cout << "1" << endl;
    }
    else
    {
        power=2;
        minpoz=0;
        minres=36893488147419103231;
        while(da)
        {
            trenres=0;
            for(int i=0;i<n;i++)
            {
                if((brojevi[i]%power)/(power/2)==0)
                    {
                        if(brojevi[i]>=power/2)
                            trenres+=min(brojevi[i]%power+1,power/2);
                        else trenres+=power/2;
                    }
            }
            if(minres>=trenres)
            {
               minres=trenres;
               minpoz=log2(power);
               minpower=power;
            }
            power*=2;
            da=false;
            for(int i=0;i<n;i++)
                if(power<=brojevi[i]*2)
                {
                    da=true;
                }
        }
        for(int i=0;i<n;i++)
            {
                if(brojevi[i]>=minpower/2)
                {
                    if(brojevi[i]%minpower+1>minpower/2)
                    {
                        brojevi[i]+=minpower/2;
                    }
                    else if(brojevi[i]%minpower+1<minpower/2)
                    {
                        brojevi[i]-=brojevi[i]%(minpower)+1;
                    }
                    else
                    {
                        if((brojevi[i]%4)/2==0 && brojevi[i]%2==1)
                            uf=true;
                        brojevi[i]+=minpower/2;
                        if(brojevi%minpower==minpower-1)
                            ej++;
                    }
                }
                else brojevi[i]+=minpower/2;
            }
        xorovan=brojevi[0];
        for(int i=1;i<n;i++)
            xorovan^=brojevi[i];
        if(xorovan!=0)
            cout << minres << endl;
        else
        {
            if(minpoz==1 && uf)
            {
                cout << minres << endl;
            }
            else if(minpoz==1 && !uf)
            {
                cout << minres+2 << endl;
            }
            else
            {
                if(ej%2==0)
                {
                    cout << minres-ej+1 << endl;
                }
                else cout >> minres-ej<<endl;
            }
        }
    }
}