N = int(eval(input()))

ori = [int(i) for i in input().split()]

count = ori.count(1)

if count == 0:

    print((-1))



else:

    savepoint = 0

    for j in range(1,N+1):

        for i in range(savepoint,N):

            if ori[i] == j:

                savepoint = i

                #print(savepoint)

                #print(j,i)

                sub = j

                break

        if i == N-1:

            break

    print((N-sub))
N=int(eval(input()))

a=[int(i) for i in input().split()]

if a.count(1)==0:

    print((-1))

else:

    ans=[]

    for i in range(N):

        if a[i]==len(ans)+1:

            ans.append(a[i])

    #print(N)

    #print(len(ans))

    print((N-len(ans)))  
N = int(eval(input()))
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print((-1))
else:
    savepoint = 0
    for j in range(1, N + 1):
        for i in range(savepoint, N):
            if ori[i] == j:
                savepoint = i
                # print(savepoint)
                # print(j,i)
                sub = j
                break
        if i == N - 1:
            break
    print((N - sub))

N = int(eval(input()))
a = [int(i) for i in input().split()]
if a.count(1) == 0:
    print((-1))
else:
    ans = []
    for i in range(N):
        if a[i] == len(ans) + 1:
            ans.append(a[i])
    # print(N)
    # print(len(ans))
    print((N - len(ans)))

-ori = [int(i) for i in input().split()] -count = ori.count(1) -if count == 0: +a = [int(i) for i in input().split()] +if a.count(1) == 0: -    savepoint = 0 -    for j in range(1, N + 1): -        for i in range(savepoint, N): -            if ori[i] == j: -                savepoint = i -                # print(savepoint) -                # print(j,i) -                sub = j -                break -        if i == N - 1: -            break -    print((N - sub)) +    ans = [] +    for i in range(N): +        if a[i] == len(ans) + 1: +            ans.append(a[i]) +    # print(N) +    # print(len(ans)) +    print((N - len(ans)))