#include <iostream>
#define ll long long
using namespace std;
ll d[70];
ll v[70];
bool eq[70];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    ll x, p, mi, pl, msk, pom;
    cin >> n;
    for(ll i = 0; i < n; i++)
    {
        cin >> x;
        for(ll j = 1; j < 6; j++)
        {
            if((x >> (j - 1)) % 2 == 0)
            {
                //cout << x << " " << j << " j\n";
                msk = ~((~0)<<j);
                pl = msk - (msk&x) + 1;
                if(x > msk) mi = (msk&x) + 1;
                else msk = LLONG_MAX;
                pom = x;
                if(pl < mi)
                {
                    pom >>= (j - 1);
                    pom++;
                    pom <<= (j - 1);
                    d[j] += pl;
                    v[j] ^= pom;
                }
                else if(mi < pl)
                {
                    msk <<= 1;
                    msk++;
                    pom |= msk;
                    d[j] += mi;
                    v[j] ^= pom;
                }
                else eq[j] = 1;
            }
            else for(ll j = 1; j < 6; j++)
                v[j] ^= x;
        }
    }
    ll m = LLONG_MAX;
    for(ll i = 1; i < 6; i++)
    {
        if(v[i] == 0)
            if(eq[i] == 0)
                d[i]+=2;
        //if(d[i] == 0) cout << i << " i\n";
        if(d[i] < m) m = d[i];
    }
    cout << m;
}