#include <iostream>
#include <unordered_map>

using namespace std;

long long n, a[100000 + 10], result = 0;
unordered_map<long long, long long> u;

void read() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        result = result ^ a[i];
        u[a[i] ^ (a[i] - 1)] = 1;
    }
}

long long solve() {
    long long x  = 0;
    for(int i = 30; i >= 0; i--) {
        if(result & (1LL << i)) {
            if(u.find((1LL << (i + 1)) - 1LL) != u.end()) {
                x++;
                result = result ^ ((1LL << (i + 1)) - 1LL);
            } else {
                return -1;
            }
        }
    }
    return x;
}

int main()
{
    read();
    cout << solve();
    return 0;
}