#include <cstdlib>
#include <cstdio>
#define gr 500010
#define ll long long
ll a[gr];
ll r[61];
inline ll manje(ll aaa,ll bbb){if(aaa<bbb)return aaa;return bbb;}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i)scanf("%d",a+i);
    r[0]=0;
    for(int i=0;i<n;++i)if((a[i]&1)==0)++r[0];
    bool sven=true;
    for(int i=0;i<n;++i)if((a[i]>1)&&((a[i]&1)==0)){sven=false;break;}
    if(sven)r[0]+=2*((n+1)&1);
    ll b=2;
    for(int s=1;s<61;++s)
    {
        r[s]=0;
        ll xr=0;
        for(int i=0;i<n;++i)
        {
            if((a[i]&b)==0)
            {
                ll xxx=b-(a[i]&(b-1));
                ll yyy=b+1-xxx;
                if(((a[i]&(b-1))==a[i])||(xxx<yyy))
                {
                    r[s]+=xxx;
                    xr^=a[i]+xxx;
                }
                else
                {
                    r[s]+=yyy;
                    xr^=a[i]-yyy;
                }
                if(r[s]>1000000)break;
            }
            else xr^=a[i];
        }
        if(xr==0)++r[s];
        b<<=1;
    }
    ll res=r[0];
    for(int i=1;i<61;++i)
        if(r[i]<res)res=r[i];
    printf("%lld\n",res);
    return 0;
}