#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
lld a[MAXN], b[MAXN], rez;
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
    int N; cin >> N;
    rez = LINF;
    for(int i = 1; i <= N; i++) cin >> a[i];
    for(int k = 1; k <= 32; k++) {
        lld xorr = 0, sum = 0;
        for(int i = 1; i <= N; i++) {
            lld manji = (((a[i]>>k)-1)<<k), veci = (((a[i]>>k)+1)<<k);
            if((1<<k)&a[i]) b[i] = a[i];
            else if(veci-a[i] < a[i]-manji) {
                b[i] = veci;
            } else b[i] = manji;
            //PRINT(i);
            //PRINT(b[i]);
            xorr ^= b[i];
            sum += abs(b[i]-a[i]);
        }
        rez = min(rez, sum + (xorr==0));
    }
    lld xorr = 0, sum = 0;
    for(int i = 1; i <= N; i++) {
        if(a[i]%2==0) a[i]++, sum++;
        xorr ^= a[i];
    }
    rez = min(rez, sum+(xorr==0)*2);
    cout << rez;
    return 0;
}