# cf16-exhibition-final-openC - Cheating Nim

def main():

    # player is second move -> make xor 0

    N, *A = list(map(int, open(0)))

    A.sort(reverse=1)

    ans, x, flg = 0, 0, [0] * 30

    for i in A:

        x ^= i

        p = bin(i ^ i - 1)[::-1].rfind("1")  # rightmost bits of i^i-1

        flg[p] = 1

    for i in range(29, -1, -1):

        p = 2 ** i

        if x & p:  # i-th bit is on

            if flg[i]:  # possible to erase i-th bit of x

                x ^= p - 1

                ans += 1

            else:

                print((-1))

                return

    print(ans)





if __name__ == "__main__":

    main()
# cf16-exhibition-final-openC - Cheating Nim

from functools import reduce

from operator import xor





def main():

    # player is second move -> make xor 0

    N, *A = list(map(int, open(0)))

    # A.sort(reverse=1)

    X, changeable, cand = reduce(xor, A), {x ^ (x - 1) for x in A}, []

    while X:

        i = (1 << X.bit_length()) - 1

        cand.append(i)

        X ^= i

    ans = 0

    for i in cand:

        if i in changeable:

            ans += 1

        else:

            print((-1))

            return

    print(ans)





if __name__ == "__main__":

    main()
# cf16-exhibition-final-openC - Cheating Nim
def main():
    # player is second move -> make xor 0
    N, *A = list(map(int, open(0)))
    A.sort(reverse=1)
    ans, x, flg = 0, 0, [0] * 30
    for i in A:
        x ^= i
        p = bin(i ^ i - 1)[::-1].rfind("1")  # rightmost bits of i^i-1
        flg[p] = 1
    for i in range(29, -1, -1):
        p = 2**i
        if x & p:  # i-th bit is on
            if flg[i]:  # possible to erase i-th bit of x
                x ^= p - 1
                ans += 1
            else:
                print((-1))
                return
    print(ans)


if __name__ == "__main__":
    main()

# cf16-exhibition-final-openC - Cheating Nim
from functools import reduce
from operator import xor


def main():
    # player is second move -> make xor 0
    N, *A = list(map(int, open(0)))
    # A.sort(reverse=1)
    X, changeable, cand = reduce(xor, A), {x ^ (x - 1) for x in A}, []
    while X:
        i = (1 << X.bit_length()) - 1
        cand.append(i)
        X ^= i
    ans = 0
    for i in cand:
        if i in changeable:
            ans += 1
        else:
            print((-1))
            return
    print(ans)


if __name__ == "__main__":
    main()

+from functools import reduce +from operator import xor + + -    A.sort(reverse=1) -    ans, x, flg = 0, 0, [0] * 30 -    for i in A: -        x ^= i -        p = bin(i ^ i - 1)[::-1].rfind("1")  # rightmost bits of i^i-1 -        flg[p] = 1 -    for i in range(29, -1, -1): -        p = 2**i -        if x & p:  # i-th bit is on -            if flg[i]:  # possible to erase i-th bit of x -                x ^= p - 1 -                ans += 1 -            else: -                print((-1)) -                return +    # A.sort(reverse=1) +    X, changeable, cand = reduce(xor, A), {x ^ (x - 1) for x in A}, [] +    while X: +        i = (1 << X.bit_length()) - 1 +        cand.append(i) +        X ^= i +    ans = 0 +    for i in cand: +        if i in changeable: +            ans += 1 +        else: +            print((-1)) +            return