#include <bits/stdc++.h>
using namespace std;
    int a[20010];
    int n,k;
    int b,c;
int main(){
    cin >> n >> k;
    for(int j=1; j<=n; j++){
        cin >> a[j];
    }
    for(int j=1; j<=n; j++){
        if(a[j]==k and a[j+1]!=0){
            cout << a[j+1] << endl;
        }
        else if(a[j]==k and a[j+1]==0){
            cout << a[1] << endl;
        }
    }

    return 0;
}