program main
	implicit none
	integer(8):: N,i,j,t,B,K
	integer,dimension(1:2*10**5)::B1,A    	
	read *, N, K 
    read(*,*) (A(i), i = 1, N)
    
	B1(1)=A(1)
	do i=2,K
	B1(i)=A(B1(i-1))
	end do

	print '(i0)',B,k
			
end program main