#include <iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
using namespace std;

long long int st[70],a[500005],f[70],p[500005],s[500005];
bool mg[500005][70];

int main()
{
    ios::sync_with_stdio(false);

    long long int n,i,j,k,x,t,res,pot,m,ks,glup=0,M;

    cin>>n;
    for(i=1;i<=n;i++) cin>>a[i];

    st[0]=1;
    for(i=1;i<=62;i++) st[i]=st[i-1]*2;

    res=M=st[60];


    for(j=0;j<=60;j++)  //m je mesto gde ce biti sve jedinice
    {

        pot=0;  ks=0;  glup=0;

        for(i=1;i<=n;i++)
        {
          if((a[i]&st[j])==st[j]) {p[i]=0; s[i]+=st[j];}
          else
          {
             if(a[i]==s[i]) p[i]=st[j]-s[i];
             else if((s[i]+1)<(st[j]-s[i])) p[i]=-1*(s[i]+1);
             else  if((s[i]+1)==(st[j]-s[i])) {p[i]=-1*(s[i]+1); f[j]=1;}
             else p[i]=st[j]-s[i];
          }
        }


        for(i=1;i<=n;i++)
            {pot+=abs(p[i]);
            if(pot>M)  {glup=1; break;}
             x=a[i]+p[i];  ks=ks^x;}

         if(glup) continue;

        //cout<<" "<<m<<" "<<pot<<" "<<ks<<endl;

        if(ks==0 && f[j]==0)
        {

            if(j!=0) pot+=1;
            else pot+=2;
        }

        res=min(res,pot);
    }

    /*
    4
    5 2 3 3

    5
    5 3 4 1 0

    */

    cout<<res;

    return 0;
}