using System;

namespace Madjionicar
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] brojevi = Console.ReadLine().Split();
            int N = Convert.ToInt32(brojevi[0]);
            int K = Convert.ToInt32(brojevi[1]);
            int[] niz = new int[N];
            int ind = 0;
            string s = Console.ReadLine();
            string[] karte = s.Split(" ");
            bool k = false;
            for (int i = 0; i < niz.Length; i++)
            {            
                niz[i] = int.Parse(karte[i]);
                if (niz[i] == K) ind = i;            
            }
            if (ind == N - 1) Console.WriteLine(niz[0]);
            else Console.WriteLine(niz[ind + 1]);
        }
    }
}