def main():

    from collections import deque

    n, *a = list(map(int, open(0).read().split()))

    a = deque(a)



    tar = 1

    gab = 0

    while a:

        i = a.popleft()

        if i != tar:

            gab += 1

        else:

            tar += 1



    if gab == n:

        print((-1))

    else:

        print(gab)





if __name__ == '__main__':

    main()

def main():

    n, *a = list(map(int, open(0).read().split()))

    

    g = 0

    t = 1

    for x in a:

        if x == t:

            t += 1

        else:

            g += 1



    print((g if g != n else -1))





if __name__ == '__main__':

    main()

def main():
    from collections import deque

    n, *a = list(map(int, open(0).read().split()))
    a = deque(a)
    tar = 1
    gab = 0
    while a:
        i = a.popleft()
        if i != tar:
            gab += 1
        else:
            tar += 1
    if gab == n:
        print((-1))
    else:
        print(gab)


if __name__ == "__main__":
    main()

def main():
    n, *a = list(map(int, open(0).read().split()))
    g = 0
    t = 1
    for x in a:
        if x == t:
            t += 1
        else:
            g += 1
    print((g if g != n else -1))


if __name__ == "__main__":
    main()

-    from collections import deque - -    a = deque(a) -    tar = 1 -    gab = 0 -    while a: -        i = a.popleft() -        if i != tar: -            gab += 1 +    g = 0 +    t = 1 +    for x in a: +        if x == t: +            t += 1 -            tar += 1 -    if gab == n: -        print((-1)) -    else: -        print(gab) +            g += 1 +    print((g if g != n else -1))