#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
const int N=5e5+5;const int MX=31;
int a[N];
pii neededToSetBit(int x,int bit){
    //printf("x:%d\n",x);
    if(bit==0){
        if(x==0){
            return{1,1};
        }
        if(x&1){
            return{0,1};
        }
        else{
            return{1,2};
        }
    }
    int mod=(1<<(bit))-1;
    //printf("mod:%d\n",mod);
    int aleft=x&mod;
    int aright=2*(mod+1);
    aright+=aleft;
    //printf("aleft:%d aright:%d\n",aleft,aright);
    int ldist=mod+1-aleft;
    int rdist=aright-mod-1;
    //printf("ldist:%d rdist:%d\n",ldist,rdist);
    if(x&(1<<bit)){
       // printf("yep\n");
        return {0,1};
    }
    if(x<(1<<bit)){
        //can't use rdist
        return {ldist,1};
    }
    if(ldist==rdist){
        return {ldist,2};
    }
    if(ldist<rdist){
        return {ldist,1};
    }
    if(ldist>rdist){
        return {rdist,1};
    }
    assert(false);
}
int main()
{
    int n;
    //neededToSetBit(8,1);
    scanf("%d",&n);
    forn(i,1,n){
        scanf("%d",&a[i]);
    }
    ll ans=1e17;
    forn(bit,0,MX-1){
        ll currans=0;bool ok=false;
        //printf("bit:%d\n",bit);
        forn(i,1,n){
            pii bs=neededToSetBit(a[i],bit);
           // printf("needed for a[%d]:%d bit:%d bs.f:%d,bs.s:%d\n",i,a[i],bit,bs.f,bs.s);
            currans+=bs.f;
            if(bs.s==2){
                ok=true;
            }
        }
        if(!ok){
            if(bit==0){
                currans++;
            }
            else{
                currans+=2;
            }
        }
        ans=min(ans,currans);
    }
    printf("%lld\n",ans);
    return 0;
}
/*
4
5 2 3 3
//
4
1 7 8 3
*/