awk -M '\
NR==1{N=$1; K=$2}
NR==2{split($0,A)}
END{
    S = 1;
    D[S]++
    B[++cnt] = S
    C[S] = cnt
    while(1){
        S = A[S];
        D[S]++
        if(D[S]>1){
            for(i=C[S];i<=cnt;i++){
                G[++c] = B[i]
            }
            break;
        }
        B[++cnt] = S
        C[S] = cnt
    }
    if(K<cnt-c){
        print B[K-1]
        exit
    }
    #print cnt
    #for(i=1;i<=c;i++)print i,G[i]
    print G[(K-cnt+c)%c+1]
}'