program main
  implicit none
  
  integer :: n,a(100000),i,j,c=0,f=1
  
  read(*,*)n
  do i = 1, n
    read(*,*)a(i)
  end do
  
  do i = 1, n
    c = c + 1 
    f = a(f)
    if (f == 2) then
      write(*,*)c
      stop
    end if
  end do
  write(*,*)-1
end program main
    