program main
      implicit none
      integer(16) :: n, k, cnt, roop, i, cnt2, waru
      integer, allocatable :: a(:)
      integer :: str, next, str2, str3
      logical, allocatable :: used(:)

      read *, n, k
      allocate( a(n) )
      read *, a

      allocate( used(n) )
      used = .false.
      cnt = 0
      str = 1
      do
        if ( used(str) ) exit
        used(str) = .true.
        next = a(str)
        str = next
        cnt = cnt + 1
      end do

      str2 = 1
      cnt2 = 1
      do
        next = a(str2)
        str2 = next
        if ( next == str ) exit
        cnt2 = cnt2 + 1
      end do

      if ( (cnt+cnt2) >= k ) then
        str3 = 1
        do i = 1, k
          next = a(str3)
          str3 = next
        end do
        print *, next
      else

        waru = cnt-cnt2
        if ( waru == 0 ) then
          waru = cnt
        end if
  
        roop = mod( k-cnt,waru )
  
        do i = 1, roop
          next = a(str)
          str = next
        end do
        print *, next
      end if

end program main

