#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int n, m;
	cin>>n>>m;
	int karteXD[n];
	int rez;
	for(int i=0; i<n; i++)
	{
	 	cin>>karteXD[i];	
	}
	for(int i=0; i<n; i++)
	{
		if(karteXD[i]==m)
		{
			if(i==(n-1))
			{
				rez = karteXD[0];
			} else {
				rez = karteXD[i-1];
			}
		}
	}
	
	cout<<rez;
	
}