n = int(eval(input()))

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



bt = 0 #break times

i = 0  

j = 0  #iterator



while i < n:

  while j < n:

    if array[j] == i+1:

      bt += 1

      break

      

    else:

      if j == n-1:

        if i == 0:

          bt = -1

          i = n+1

          j = n+1

          break

        else:

          i = n+1

          j = n+1

          break

          

    j += 1

  i +=1

  

if bt != -1:

  bt = n - bt

  

print(bt)
n = int(eval(input()))

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



i = 0

j = 0

bt = 0



while i < n:

  while j < n - i:

    if a[i+j] == i+1:

      bt += 1

      break

    if j + i == n-1:

      if i == 0:

        bt = -1

      j = n + 1

      i = n + 1

      

    j += 1

  i += 1

  

if bt != -1:

  bt = n - bt

  

print(bt)
n = int(eval(input()))
array = list(map(int, input().split()))
bt = 0  # break times
i = 0
j = 0  # iterator
while i < n:
    while j < n:
        if array[j] == i + 1:
            bt += 1
            break
        else:
            if j == n - 1:
                if i == 0:
                    bt = -1
                    i = n + 1
                    j = n + 1
                    break
                else:
                    i = n + 1
                    j = n + 1
                    break
        j += 1
    i += 1
if bt != -1:
    bt = n - bt
print(bt)

n = int(eval(input()))
a = list(map(int, input().split()))
i = 0
j = 0
bt = 0
while i < n:
    while j < n - i:
        if a[i + j] == i + 1:
            bt += 1
            break
        if j + i == n - 1:
            if i == 0:
                bt = -1
            j = n + 1
            i = n + 1
        j += 1
    i += 1
if bt != -1:
    bt = n - bt
print(bt)

-array = list(map(int, input().split())) -bt = 0  # break times +a = list(map(int, input().split())) -j = 0  # iterator +j = 0 +bt = 0 -    while j < n: -        if array[j] == i + 1: +    while j < n - i: +        if a[i + j] == i + 1: -        else: -            if j == n - 1: -                if i == 0: -                    bt = -1 -                    i = n + 1 -                    j = n + 1 -                    break -                else: -                    i = n + 1 -                    j = n + 1 -                    break +        if j + i == n - 1: +            if i == 0: +                bt = -1 +            j = n + 1 +            i = n + 1