#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int niz[n];
    int ind;
    for(int i=0;i<n;i++)
    {
        cin>>niz[i];
        if(niz[i]==m)
            ind=i;
    }
    if(ind==n-1)
        cout<<niz[0];
    else
        cout<<niz[ind+1];
    return 0;
}