from collections import deque

n = int(eval(input()))

r = deque(list(map(int, input().split())))

i=0

while True:

    if max(len(r),i)==i:

        break

    if r[i]!=i+1:

        r.popleft()

    else:

        i+=1

print(('-1' if len(r)==0 else n-len(r)))
n = int(eval(input()))

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

c, i = 0, 1

for r in R:

  if r==i: i+=1

  else: c+=1

print((c if c<n else '-1'))

from collections import deque

n = int(eval(input()))
r = deque(list(map(int, input().split())))
i = 0
while True:
    if max(len(r), i) == i:
        break
    if r[i] != i + 1:
        r.popleft()
    else:
        i += 1
print(("-1" if len(r) == 0 else n - len(r)))

n = int(eval(input()))
R = list(map(int, input().split()))
c, i = 0, 1
for r in R:
    if r == i:
        i += 1
    else:
        c += 1
print((c if c < n else "-1"))

-from collections import deque - -r = deque(list(map(int, input().split()))) -i = 0 -while True: -    if max(len(r), i) == i: -        break -    if r[i] != i + 1: -        r.popleft() +R = list(map(int, input().split())) +c, i = 0, 1 +for r in R: +    if r == i: +        i += 1 -        i += 1 -print(("-1" if len(r) == 0 else n - len(r))) +        c += 1 +print((c if c < n else "-1"))