#include <bits/stdc++.h>
using namespace std;
#define int long long
#define bit(a, i) ((a>>i)&1)

const int mx = 5e5+5, bt = 60;
int n, a[mx];
int dp[mx][bt], sum[mx][bt];
int dpDod[mx][bt], dpOd[mx][bt];

void debug() {
    cout << "-----DEBUG-----" << '\n';
    for (int i = 1; i <= n; i++) {
        for (int j = bt-1; j >= 0; j--)
            cout << sum[i][j] << ' ';
        cout << '\n';
    }
    cout << '\n';
    for (int i = 1; i <= n; i++) {
        for (int j = bt-1; j >= 0; j--)
            cout << dpDod[i][j] << ' ';
        cout << '\n';
    }
    cout << '\n';
    for (int i = 1; i <= n; i++) {
        for (int j = bt-1; j >= 0; j--)
            cout << dpOd[i][j] << ' ';
        cout << '\n';
    }
    cout << '\n';
    for (int i = 1; i <= n; i++) {
        for (int j = bt-1; j >= 0; j--)
            cout << dp[i][j] << ' ';
        cout << '\n';
    }
    cout << "-----DEBUG-----" << '\n';
}

bool check() {
    int xs = 0, an = 1;
    for (int i = 1; i <= n; i++) {
        xs ^= a[i];
        an &= a[i];
    }
    return an && xs;
}

int solve(int ch) {
    int ans = 1e9;
    if (check()) return 0;
    if (ch >= 8) return ans;
    for (int i = 1; i <= n; i++) {
        a[i]++;
        ans = min(solve(ch+1)+1, ans);
        a[i]-=2;
        ans = min(solve(ch+1)+1, ans);
        a[i]++;
    }
    return ans;
}

void brute() {
    cout << solve(0);
    exit(0);
}

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

    if (n <= 16) brute();

    for (int i = 1; i <= n; i++) {
        sum[i][0] = a[i] & 1;
        dpDod[i][0] = dpOd[i][0] = 1;
        int pw = 1;
        for (int j = 1; j < bt; j++) {
            pw <<= 1;
            sum[i][j] = bit(a[i], j) * pw + sum[i][j-1];
            dpDod[i][j] = pw - sum[i][j-1];
            dpOd[i][j] = sum[i][j-1] + 1;
        }
    }

    //debug();


    int ans = 1e18;

    for (int j = 0; j < bt; j++) {
        int tans = 0;
        for (int i = 1; i <= n; i++) {
            tans += (!bit(a[i], j)) * min(dpDod[i][j], dpOd[i][j]);
        }
        ans = min(ans, tans);
    }

    cout << ans;
}