#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define lld long long
#define LINF 1000000000000000000LL
using namespace std;
#define MAXN 500010
#define MAXL 40
lld a[MAXN], b[MAXN], rez, pre[MAXL];
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
    int N; cin >> N;
    rez = LINF;
    pre[0] = 1;
    for(int i = 1; i < MAXL; i++) pre[i] = pre[i]*2+1;
    for(int i = 1; i <= N; i++) cin >> a[i];
    for(int k = 0; k < MAXL; k++) {
        lld xorr = 0, sum = 0, jednako = 0;
        for(int i = 1; i <= N; i++) {
            lld manji = ((a[i]>>k) == 0 ? -LINF:(((a[i]>>k)-1)<<k)+(k>0?pre[k-1]:0)), veci = (((a[i]>>k)+1)<<k);
            if((1LL<<k)&a[i]) {
                b[i] = a[i];
            }
            else if(veci-a[i] < a[i]-manji) {
                b[i] = veci;
            } else if(veci-a[i] > a[i]-manji) {
                b[i] = manji;
            } else {
                jednako = 1;
                b[i] = manji;
            }
            xorr ^= b[i];
            sum += abs(b[i]-a[i]);
        }
        if(k != 0) rez = min(rez, sum + (xorr==0&&jednako==0));
        if(k == 0) rez = min(rez, sum + 2*(xorr==0&&jednako==0));
    }
    cout << rez;
    return 0;
}