#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    vector<int> u(N);
    int xsum = 0;
    for(int i=0; i<N; ++i) {
        cin >> v[i];
        u[i] = v[i] ^ (v[i] - 1);
        xsum ^= v[i];
    }
    sort(u.begin(), u.end());
    u.erase(unique(u.begin(), u.end()), u.end());
    int res = 0;
    for(int i=30; i>=0; --i) {
        if(xsum & (1 << i) && binary_search(u.begin(), u.end(), (1 << (i+1)) - 1)) {
            xsum ^= (1 << (i+1)) - 1;
            res++;
        }
    }
    if(xsum != 0) {
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }
}
