n=int(eval(input()))

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

cnt=0

#n=200000

if 1 not in a:

  print((-1));exit()

from collections import*  

b=deque(a)

#print(b)

i=1

while True:

  if len(b)==0:

    break

  if b[0]==i:

    cnt+=0

    b.popleft()

    i+=1

  else:

    cnt+=1

    b.popleft()

  #print(b,cnt)     



print(cnt)
from collections import*

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





def main():

  

  if 1 not in a:

    print((-1));exit()



  b=deque(a)

  #print(b)



  i=1

  cnt=0

  while True:



    if len(b)==0:

      break



    if b[0]!=i:

      cnt+=1

      b.popleft()



    else:#b[0]==i

      cnt+=0

      b.popleft()

      i+=1



    #print(b,cnt)



  print(cnt)



  

main()
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
# n=200000
if 1 not in a:
    print((-1))
    exit()
from collections import *

b = deque(a)
# print(b)
i = 1
while True:
    if len(b) == 0:
        break
    if b[0] == i:
        cnt += 0
        b.popleft()
        i += 1
    else:
        cnt += 1
        b.popleft()
    # print(b,cnt)
print(cnt)

from collections import *

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


def main():
    if 1 not in a:
        print((-1))
        exit()
    b = deque(a)
    # print(b)
    i = 1
    cnt = 0
    while True:
        if len(b) == 0:
            break
        if b[0] != i:
            cnt += 1
            b.popleft()
        else:  # b[0]==i
            cnt += 0
            b.popleft()
            i += 1
        # print(b,cnt)
    print(cnt)


main()

-n = int(eval(input())) -a = list(map(int, input().split())) -cnt = 0 -# n=200000 -if 1 not in a: -    print((-1)) -    exit() -b = deque(a) -# print(b) -i = 1 -while True: -    if len(b) == 0: -        break -    if b[0] == i: -        cnt += 0 -        b.popleft() -        i += 1 -    else: -        cnt += 1 -        b.popleft() -    # print(b,cnt) -print(cnt) +n, *a = list(map(int, open(0).read().split())) + + +def main(): +    if 1 not in a: +        print((-1)) +        exit() +    b = deque(a) +    # print(b) +    i = 1 +    cnt = 0 +    while True: +        if len(b) == 0: +            break +        if b[0] != i: +            cnt += 1 +            b.popleft() +        else:  # b[0]==i +            cnt += 0 +            b.popleft() +            i += 1 +        # print(b,cnt) +    print(cnt) + + +main()