#include <iostream>
#include <iomanip>

using namespace std;

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

void karta(unsigned a[],int n,int k)
{
    int l=0,r=n-1,m;
    while(l<=r)
    {
        m=l+(r-l)/2;
        if(a[m]==k)
        {
            if(m==n-1)
            cout<<a[0];
            else
                cout<<a[m+1];
            break;
        }

        if(k>a[m])
            l=m+1;
        if(k<a[m])
            r=m-1;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    unsigned n,k;
    cin>>n>>k;
    unsigned a[n];
    unos(a,n);
    karta(a,n,k);

    return 0;
}