#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=500050;
const ll inf=9e18;
ll a[N],b[N],c[N];
bool both;
int main()
{
	int n,i,j;
	scanf("%i",&n);
	for(i=1;i<=n;i++) scanf("%lld",&a[i]);
	ll ans=inf;
	for(j=0;j<=61;j++)
	{
		ll bt=(ll)1<<j;
		ll sum=0;
		both=0;
		for(i=1;i<=n;i++)
		{
			if(a[i]&bt){ c[i]=0;continue;}
			ll tmp=bt-(a[i]%bt);
			c[i]=tmp;
			if(a[i]>bt)
			{
				if(tmp>(a[i]%bt)+1)
					tmp=min(tmp,(a[i]%bt)+1),c[i]=-tmp;
				else if(tmp==(a[i]%bt)+1) both=1;
			}
			sum+=tmp;
			if(sum>ans) break;
		}
		if(sum>ans) continue;
		int add=0;
		ll xr=0;
		for(i=1;i<=n;i++)
		{
            b[i]=a[i]+c[i];
            xr^=b[i];
		}
		if(xr==0) add=1;
		if(both) add=0;
		if(j==0 && add) add++;
		sum+=add;
		ans=min(ans,sum);
	}
	printf("%lld\n",ans);
	return 0;
}