n = int(eval(input()))

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

flag = -1

for i in range(n):

    if s[i] == 1:

        flag = 2

    if s[i] == flag:

        flag += 1

if flag == -1:

    print((-1))

else:

    print((n - flag + 1))
n = int(eval(input()))

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

flag = 1

for i in range(n):

    if s[i] == flag:

        flag += 1

if 1 not in s:

    print((-1))

else:

    print((n - flag +1))
n = int(eval(input()))
s = list(map(int, input().split()))
flag = -1
for i in range(n):
    if s[i] == 1:
        flag = 2
    if s[i] == flag:
        flag += 1
if flag == -1:
    print((-1))
else:
    print((n - flag + 1))

n = int(eval(input()))
s = list(map(int, input().split()))
flag = 1
for i in range(n):
    if s[i] == flag:
        flag += 1
if 1 not in s:
    print((-1))
else:
    print((n - flag + 1))

-flag = -1 +flag = 1 -    if s[i] == 1: -        flag = 2 -if flag == -1: +if 1 not in s: