#include <iostream>
#include <bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;a++)
#define ll long long
using namespace std;
const int MAX=5*1e5+5,INF=1e18+7;

ll rez=INF,a[MAX],temp[MAX];
int n;


ll resi_bit (int b)
{
    ll tmp1=0,tmp2=0,sum=0;
    ll curr=0;
    For(i,1,n)
    {   tmp1=0,tmp2=0;temp[i]=0;
        if (a[i]&(1<<b))
        {
            temp[i]=a[i];
        }
        else
        if (a[i]<(1<<b))
        {
            temp[i]=(1<<b);
            curr+=(1<<b)-a[i];

        }
        else
        if (a[i]>(1<<b))
        {
            tmp1=(1<<b)-a[i]%(1<<b);

            sum=0;
            tmp2[i]=a[i]%(1<<b)+1;
            if (tmp1<=tmp2)
            {
                temp[i]=a[i]+tmp1;
                curr+=tmp1;
            }
            else
            {
                temp[i]=a[i]-tmp2;
                curr+=tmp2;
            }
        }

    }
    bool ok=false;
    int tempok;
    if (n%2==1) return curr;
    For(i,0,30)
    {
        tempok=0;
        For(j,1,n)
        {
           if  (temp[j]&(1<<i)) tempok++;
        }
        if (tempok%2==1) ok=true;
    }
    if (ok) return curr;
    else return curr+1;

}

int main()
{
    cin>>n;
    For(i,1,n)
    scanf("%I64d",&a[i]);
    For(i,0,30)
    {
        //cout<<resi_bit(i)<<" ";
        //cout<<i<<" "<<resi_bit(i)<<endl;
        rez=min(rez,resi_bit(i));
    }

    cout<<rez;

    return 0;
}
/*
4
5 2 3 3
*/