#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;

int N,tmp=0,ans=0;
int cnt[100010];

signed main() {
    IOS();
    cin>>N;
    vint a(N);
    rep(i,0,N){
        cin>>a[i];
        tmp^=a[i];
        int t=0;
        while(a[i]%2==0){
            t++;
            a[i]/=2;
        }
        cnt[t]++;
    }
    rrep(i,0,31){
        if(cnt[i]==0&&((1ll<<i)&tmp)){
            cout<<-1<<endl;
            return 0;
        }
        if(cnt[i]==0||(((1ll<<i)&tmp)==0))continue;
        tmp^=(1ll<<i);
        tmp^=(1ll<<i)-1;
        ans++;
        if(tmp==0)break;
    }
    if(tmp){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    
    
    
    
    
    return 0;
}