#include <bits/stdc++.h>
using namespace std;
int niz[20005],N,K;
int main() {
    cin >> N >> K;
    for (int n=1;n<=N;n++){
        cin >> niz[n];

    }
    for (int i=1;i<=N;i++){
         if (K==niz[i] and i!=1 and i!=N)
             cout << niz[i-1] << endl;
         if (K==niz[i] and i==N)
             cout << niz[1] << endl;
         if (K==niz[i] and i==1)
             cout << niz[i+1] << endl;
    }
    return 0;
}