#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;

int main()
{
    ios;
    long long N,K;
    int ind;
    cin>>N>>K;
    int p[N];
    for(int i =1;i<=N;i++){
        cin>>p[i];
        if(p[i]==K)ind=i;
    }
    if(ind==1)cout<<p[2];
    else if(ind==N)cout<<p[1];
    else cout<<p[ind+1];
    return 0;
}