#include<bits/stdc++.h>
#define ll long long

using namespace std;
int n;
ll a[500010];
int binarno[500010][65];
bool neparno[65];
bool nepom[65];
ll stepen2[65];
ll maxc=52;
bool joker;

void rastavi(int i)
{
    ll tek=a[i];
    for(int j=0;j<maxc && tek!=0;j++)
        binarno[i][j]=tek%2, tek/=2;
}

ll najbolje(int i, int j)
{
    if(binarno[i][j]==1)
        return 0;
    ll uvecaj=stepen2[j]-(a[i]%stepen2[j]);
    //if(stepen2[j]>a[i])
    //    return uvecaj;
    ll smanji=a[i]%stepen2[j]+1;
    return min(uvecaj,smanji);
}

ll resi(int j)
{
    ll ret=0;
    for(int i=0;i<n;i++)
        ret+=najbolje(i,j);
    return ret;
}

ll najbolje2(int i, int j)
{
    if(binarno[i][j]==1)
        return 0;
    ll uvecaj=stepen2[j]-(a[i]%stepen2[j]);
    if(stepen2[j]>a[i])
    {
        for(int p=0;p<j;p++)
            if(binarno[i][p]==1)
                nepom[p]=!nepom[p];
        return uvecaj;
    }
    ll smanji=a[i]%stepen2[j]+1;
    if(smanji==uvecaj)
        joker=true;
    if(smanji<uvecaj)
    {
        for(int p=0;p<j;p++)
            if(binarno[i][p]==0)
                nepom[p]=!nepom[p];
        for(int p=j+1;p<maxc;p++)
        {
            nepom[p]=!nepom[p];
            if(binarno[i][p]==1)
                break;
        }
        return smanji;
    }
    return uvecaj;
}

ll resi2(int j)
{
    joker=false;
    for(int i=0;i<maxc;i++)
        nepom[i]=neparno[i];
    ll ret=0;
    for(int i=0;i<n;i++)
        ret+=najbolje2(i,j);
    if(ret<0)
        return LONG_LONG_MAX;
    if(joker)
        return ret;
    for(int i=0;i<maxc;i++)
        if(nepom[i] && i!=j)
            return ret;
    if(j==0)
        return ret+2;
    return ret+1;
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    stepen2[0]=1;
    for(int i=1;i<maxc;i++)
        stepen2[i]=stepen2[i-1]*2;

    for(int i=0;i<n;i++)
        rastavi(i);

    for(int j=0;j<maxc;j++)
    {
        int sum=0;
        for(int i=0;i<n;i++)
            sum+=binarno[i][j];

        if(sum%2==1)
            neparno[j]=true;
        else
            neparno[j]=false;
    }

    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<64;j++)
            cout<<binarno[i][j];
        cout<<endl;
    }*/

    ll sol=LONG_LONG_MAX;
    if(n%2==1)
    {
        for(int j=0;j<maxc/2;j++)
            sol=min(sol,resi(j));
        cout<<sol;
    }
    else
    {
        for(int j=0;j<maxc/2;j++)
            sol=min(sol,resi2(j));
        cout<<sol;
    }
}