# cf16-exhibition-final-openC - Cheating Nim

import sys

input = sys.stdin.readline





def main():

    # player is second move -> make xor 0

    N = int(eval(input()))

    A = sorted(map(int, [eval(input()) for _ in range(N)]), reverse=1)

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

    for i in A:

        x ^= i

        p = bin(i ^ i - 1)[::-1].rfind("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

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
import sys

input = sys.stdin.readline


def main():
    # player is second move -> make xor 0
    N = int(eval(input()))
    A = sorted(map(int, [eval(input()) for _ in range(N)]), reverse=1)
    ans, x, flg = 0, 0, [0] * 30
    for i in A:
        x ^= i
        p = bin(i ^ i - 1)[::-1].rfind("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
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()

-import sys - -input = sys.stdin.readline - - -    N = int(eval(input())) -    A = sorted(map(int, [eval(input()) for _ in range(N)]), reverse=1) +    N, *A = list(map(int, open(0))) +    A.sort(reverse=1) -        p = bin(i ^ i - 1)[::-1].rfind("1") +        p = bin(i ^ i - 1)[::-1].rfind("1")  # rightmost bits of i^i-1