from collections import deque



n = int(eval(input()))

a = list(map(int, input().split()))

if 1 in a:

    d = deque(a)

    count = 0

    num = 1

    pick = 0

    while d:

        pick = d.popleft()

        count += 1

        if pick == num:

            count -= 1

            num += 1



    print(count)

else:

    print((-1))

from collections import deque



n = int(eval(input()))

a = list(map(int, input().split()))

if 1 in a:

    count = 0

    num = 1

    for i in a:

        if num == i:

            num += 1

        else:

            count += 1

    print(count)

else:

    print((-1))



from collections import deque

n = int(eval(input()))
a = list(map(int, input().split()))
if 1 in a:
    d = deque(a)
    count = 0
    num = 1
    pick = 0
    while d:
        pick = d.popleft()
        count += 1
        if pick == num:
            count -= 1
            num += 1
    print(count)
else:
    print((-1))

from collections import deque

n = int(eval(input()))
a = list(map(int, input().split()))
if 1 in a:
    count = 0
    num = 1
    for i in a:
        if num == i:
            num += 1
        else:
            count += 1
    print(count)
else:
    print((-1))

-    d = deque(a) -    pick = 0 -    while d: -        pick = d.popleft() -        count += 1 -        if pick == num: -            count -= 1 +    for i in a: +        if num == i: +        else: +            count += 1