#include <iostream>
#define MAX 20000

using namespace std;

void unos(unsigned a[], int n){
    for(int i=0;i<n;i++)
        cin >> a[i];
}

int main(){
    unsigned n, k;
    cin >> n >> k;

    if(n<2 || n>MAX || k<1 || k>n) exit(1);

    unsigned a[n];
    unos(a,n);

    for (int i = 0; i < n; i++)
    {
        if(a[i]==k){
            if(i==0)
                cout << a[n-1];
            else if(i==n-1)
                cout << a[0];
            else
                cout << a[i-1];
        }
    }
    

    return 0;
}