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

long long int st[70],a[500005],mg[500005][70],tb[500005][70];

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

    long long int n,i,j,k,x,t,p,res,pot,m,s,ks;

    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=st[60];

    // for(i=1;i<=61;i++) cout<<st[i]<<" ";

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

          //if(j<=5) cout<<i<<" "<<j<<" "<<tb[i][j]<<endl;
      }
    }

    for(m=0;m<=61;m++)  //m je mesto gde ce biti sve jedinice
    {
        pot=0;  ks=0;
        for(i=1;i<=n;i++) {pot+=abs(tb[i][m]);  x=a[i]+tb[i][m];  ks=ks^x;}

        if(ks==0)
        {
            if(m==1 && n%2==0) pot+=2;
            else pot+=1;
        }

        res=min(res,pot);
    }

    /*
    4
    5 2 3 3
    */

    cout<<res;

    return 0;
}