#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
bool f[33];

signed main(){
    cin>>N;

    int X=0;
    rep(i,N){
        int a;cin>>a;
        X^=a;
        int k=0;
        while(!(a>>k&1))k++;
        f[k]=true;
    }


    int cnt=0;
    for(int i=30;i>=0;i--){
        if(!(X>>i)&1)continue;
        if(!f[i]){
            cout<<-1<<endl;
            return 0;
        }
        X^=(1<<(i+1))-1;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
