#include <stdio.h>

int main(void){

    long N,K;
    long loop=0;
    long A[1000000];
    long cnt[1000000];
    long i=1,j;
    long now;
    long start;
    long time=0;
    long ans;

    scanf("%ld %ld", &N, &K);
    for(j=0; j<N; j++) cnt[j]=0;
    cnt[i-1]=1;
    if(N>=K){
        for(j=0; j<K; j++){
            scanf("%ld", &A[j-1]);
            now = A[j-1];
        }
    printf("%ld", now);
    }else{
        //箇所
        while(1){
            
            scanf("%ld", &A[i-1]);
            now = A[i-1];
            cnt[i-1]++;
            time++;
            start=now;
            if(cnt[i-1]==2)break;

        }
        //回数
        while(1){    
            scanf("%ld", &A[i-1]);
            now = start;
            cnt[i-1]++;
            loop++;
            if(cnt[i-1]==3)break;
        }
        
        ans = (time - start) % loop + time;
            for(j=0; j<ans; j++){
            scanf("%ld", &A[j-1]);
            now = A[j-1];
        }
        printf("%d", now);   
        
    }


    return 0;
}