#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    if(n == 2)
    {
        int a, b;
        cin >> a >> b;
        cout << a + b - k;
        return 0;
    }

    int niz[n];

    int indeks = 0;
    for (int i = 0 ; i < n ; i++)
    {
        cin >> niz[i];
        if (niz[i] == k) indeks = i;
    }

    if (indeks == n-1) cout << niz[0];
    else cout << niz[indeks + 1];
}