import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;
import core.bitop;

void main() {
    int n; scan(n);
    auto a = iota(n).map!(i => readln.chomp.to!int).array;

    auto on = new bool[](32);
    int xs;
    foreach (i ; 0 .. n) {
        on[bsf(a[i])] = 1;
        xs ^= a[i];
    }
    int ans;
    foreach_reverse (i ; 0 .. 32) {
        if ((xs >> i) & 1) {
            if (on[i]) {
                xs ^= (1<<i) - 1;
                ans++;
            }
            else {
                writeln(-1);
                return;
            }
        }
    }
    writeln(ans);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
