program main
  implicit none
  integer(8) i, see, ans, N
  integer(8),allocatable :: A(:)
  read(*, *)N
  allocate(A(N))
  read(*, *) (A(i), i = 1,N)
  ans = 0
  see = 1
  do i = 1,N
    if (A(i) == see) then
      see = see + 1
    else
      ans = ans + 1
    end if
  end do
  if (see == 1) then
    ans = -1
  end if

  write(*, *) ans
end program main
