#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    int n,xr=0,ans=0,i;set<int>avb;cin>>n;int a[n];
    for(i=0;i<n;i++)cin>>a[i],xr^=a[i],avb.insert(a[i]^(a[i]-1));
    for(i=29;i>=0;i--){
        if((xr>>i)&1){
            if(avb.count((1<<i+1)-1))xr^=(1<<i+1)-1,ans++;
            else return puts("-1")*0;
        }
    }
    cout<<ans<<endl;
}