#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int n;cin >> n;
    int sum=0;
    set<int> st;
    for (int i = 0; i < n; i++) {
        int a;cin >> a;
        sum^=a;
        int k=0;
        while(a){
            if(a&1) break;
            k++;
            a>>=1;
        }
        st.insert(k);
    }
    int ans=0;
    for (int i = 30; i >= 0; i--) {
        if(sum&(1<<i)){
            ans++;
            if(st.find(i)!=st.end()) sum^=(1<<(i+1))-1;
            else{
                puts("-1");
                return 0;
            }

        }
    }
    cout << ans << endl;
    return 0;
}
