#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int a;
    vector<int> input;
    while (cin >> a) {
        input.push_back(a);
    }
    if (k == input[0]) {
        cout << input[1] << endl;
    }
    else if (k == input[n - 1]){
        cout << input[0] << endl;
    }
    else {
        for (int i = 0; i < n; i++) {
            if (k == input[i]) {
                cout << input[i + 1] << endl;
                break;
            }
        }
    }
}