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

using namespace std;

ULL n, a[500010], pa[500010], deg[64] = {1}, cost[64], c, ans, real_ans;
bool b[500010][64];

ULL real_cost(ULL bit)
{
    bool moze = false;
    ULL temp_xor;
    for (int i = 0; i < n; ++i)
        pa[i] = a[i];
    for (int i = 0; i < n; ++i)
    {
        if (b[i][bit]) continue;
        if (a[i] < deg[bit]) pa[i] = deg[bit];
        else
        {
            if ((a[i] & (deg[bit]-1)) + 1 <= deg[bit] - (a[i] & (deg[bit]-1)))
                pa[i] = a[i] - (a[i] & (deg[bit]-1)) - 1;
            else
                pa[i] = a[i] - (a[i] & (deg[bit]-1)) + deg[bit];
            if ((a[i] & (deg[bit]-1)) + 1 == deg[bit] - (a[i] & (deg[bit]-1))) moze = true;
        }
    }
    temp_xor = pa[0];
    for (int i = 1; i < n; ++i) temp_xor ^= pa[i];
    if (temp_xor != 0) return cost[bit];
    if (bit == 0) return cost[bit] + 2;
    return cost[bit] + 1;
}

int main()
{
    for (int i = 1; i < 64; ++i)
        deg[i] = deg[i-1] << 1;
    scanf("%lld", &n);
    for (int i = 0; i < n; ++i)
        scanf("%lld", &a[i]);
    for (int i = 0; i < n; ++i)
        pa[i] = a[i];
    for (int i = 0, it = 0; i < n; ++i, it = 0)
        while (pa[i] > 0)
        {
            if (pa[i] % 2) b[i][it] = true;
            pa[i] /= 2;
            it++;
        }
    for (int i = 0; i < 64; ++i)
    {
        for (int j = 0; j < n; ++j)
            if (!b[j][i])
            {
                c = deg[i] - (a[j] & (deg[i]-1));
                if (a[j] > deg[i]) c = min((a[j] & (deg[i]-1)) + 1, c);
                cost[i] += c;
                if (cost[i] > ans + 10) break;
            }
        if (i == 0) ans = cost[i];
        else ans = min(cost[i], ans);
    }

    ans = cost[0];
    for (int i = 1; i < 64; ++i) ans = min(cost[i], ans);

    real_ans = real_cost(0);
    for (int i = 1; i < 64; ++i)
        if (cost[i] <= ans + 1)
            real_ans = min(real_cost(i), real_ans);

    // for (int i = 0; i < 64; ++i)
    //        printf("%lld ", cost[i]);

    printf("%lld", real_ans);

    return 0;
}

/*
for (int i = 0; i < 64; ++i)
    and_niz[i] = true, xor_niz[i] = false;
for (int i = 0; i < 64; ++i)
{
    for (int j = 0; j < n; ++j)
    {
        and_niz[i] = (bool)((int)and_niz[i] & (int)b[j][i]);
        xor_niz[i] = (bool)((int)xor_niz[i] ^ (int)b[j][i]);
    }
}
for (int i = 0; i < n; ++i)
{
    for (int j = 0; j < 64; ++j) printf("%i ", (int)(b[i][j]));
    printf("\n");
}
for (int i = 0; i < 64; ++i) printf("%i ", (int)(and_niz[i]));
printf("\n");
for (int i = 0; i < 64; ++i) printf("%i ", (int)(xor_niz[i]));
*/