#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, ans = 0;
    cin >> n;
    ll z = 0;
    vector<ll> a(n);
    vector<int> b(33);
    rep(i, 0, n) {
        cin >> a[i];
        z ^= a[i];
        int j = 0;
        while (!((a[i] >> j) & 1))
            j++;
        b[j]++;
    }

    for (int i = 32; i >= 0; i--) {
        if ((z >> i) & 1) {
            if (b[i] <= 0) {
                cout << -1 << endl;
                return 0;
            }
            b[i]--;
            z ^= (1 << (i + 1)) - 1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
