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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


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

    auto as = a.reduce!"a ^ b"();

    auto b = new int[](32);
    foreach (i ; 0 .. n) {
        b[bsf(a[i])]++;
    }

    debug {
        writeln("as:", as);
        writeln("b:", b);
    }

    int s = 0;
    int ans;

    foreach_reverse (i ; 0 .. 32) {
        int ai = (as >> i) & 1;
        ai ^= s;

        debug {
            writefln("i : %d, ai: %d, s: %d", i, ai, s);
        }

        if (ai) {
            if (b[i]) {
                ans++;
                s ^= 1;
            }
            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);
        }
    }
}
