program main

  implicit none!933

  integer :: n, i, j, bn, nbn
  integer, allocatable :: a(:)
  integer, allocatable :: b(:)
  logical :: breakk = .false.
   
  read(*,*) n
  allocate( a(n) )
  read(*,*) a
  allocate( b(n) )
  j = 1
  bn = 0
  nbn = 0
  do i = 1, n  
    if ( a(i) == j ) then
      bn = bn + i - 1 - nbn
      !nbn = nbn + i - 1
      nbn = i
      j = j + 1
      breakk = .true.
    endif
  end do
  if( .not. breakk ) then
    bn = -1
    print*, bn
  else
    print*, bn
  end if
end program main
