program sample
  implicit none
  integer(8) :: n,i,b
integer(8),allocatable :: a(:)
 
read(*,*) n
allocate(a(n))
do i=1,n
read(*,*) a(i)
end do
 
b=1
do i=1,n
   a(b)=b
   if(a(b)==2)then
      write(*,*) i
      stop
   endif   
end do
 
write(*,*) -1
 
end program sample