      module takahashiMod
      implicit none
      integer(16),allocatable :: a(:)
      
      contains
      
      end module
      
      program teleporter
      use takahashiMod
      implicit none
      integer(16) :: n,k
      integer(16),allocatable :: telepoNum(:)
      integer(16) :: i,start,startTown,finTown,mo, now,next
      logical,allocatable :: flag(:)
      logical piyo
      
      read*,n,k
      allocate( a(n) )
      read*,a(1:n)
print*,n,k
print*,a(:)
      
      
      allocate( telepoNum(n),flag(n) );flag = .false.
      
      telepoNum(1) = 1
      do i = 2,n
        telepoNum(i) = a( telepoNum(i-1) )
      end do
print*,telepoNum
      
      do i = 1,n
        if( flag(telepoNum(i)) )then
          start = telepoNum(i)
          exit
        else
          flag(telepoNum(i)) = .true.
        end if
        print*,flag
      end do
print*,start
      
      i = 0
      piyo = .false.
      do while(.true.)
        i = i + 1
        if( telepoNum(i)==start )then
          if( piyo )then
            finTown = i
            exit
          else
            startTown = i
          end if
          piyo = .true.
        end if
      end do
      mo = finTown - startTown
print*,startTown,finTown,mo
      k = mod( k-startTown+1,mo )
print*,k
      print*,telepoNum(k+1+(startTown-1))
      end program