#include <cstdio>
#include <cassert>
#define MAXN 100005
using namespace std;

int n;
bool can[32];

int main() {

    scanf("%d", &n);

    int nimVal = 0;
    for(int i = 1; i <= n; ++i) {
        int x;
        
        scanf("%d", &x);
        nimVal ^= x;

        int cnt = 0;
        while((x & 1) == 0) {
            ++cnt;
            x >>= 1;
        }
        can[cnt] = 1;
    }

    int sol = 0;
    for(int i = 29; i >= 0; --i) {
        if(nimVal & (1 << i)) {
            if(!can[i]) {
                return 0 * printf("-1\n");
            }
            ++sol;
            nimVal ^= ((1 << (i + 1)) - 1);
        }
    }
    assert(nimVal == 0);

    printf("%d\n", sol);

    return 0;
}