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

using namespace std;

int n;
ll a[500010];
int binarno[500010][65];
ll stepen2[65];

void rastavi(int i)
{
    ll tek=a[i];
    for(int j=0;j<65;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]);
    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;
}

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

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

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

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

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