! 2019.12.22
!
      program answer
      implicit none
      integer :: N
      integer,allocatable,dimension(:) :: a
      integer,allocatable,dimension(:) :: coun
      integer :: i
      integer :: ans
      integer :: en_con
      integer :: num
!
      read(*,*) N
      allocate(a(N),coun(N))
      read(*,*) (a(i),i=1,N)
!initialization
      do i=1,N
        coun(i) = 0
      end do
!counting
      do i=1,N
        coun(a(i)) = coun(a(i))+1
      end do
!ans = -1 condition
      if(coun(1) == 0) then
        ans = -1
        goto 9999
      end if
!calculate end condition
      en_con=N
      do i=1,N
        if(coun(i) == 0) then
          en_con=i
          exit
        end if
      end do
!determine ans
      num=1
      i=0
      lp1:do 
        i=i+1
        lp2:do 
          if(num > N) exit lp1
          if(i > en_con) exit lp1
          if(a(num) == i) exit lp2
          num=num+1
        end do lp2
      end do lp1
      ans = N-(i-1)
!output
9999  write(*,*) ans
      end program answer