using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            var jeajea = Console.ReadLine().Split();
            int n = int.Parse(jeajea[0]);
            int k = int.Parse(jeajea[1]);
            List<int> a = new List<int>();
            var jeajea1 = Console.ReadLine().Split();
            for (int i =0;i<n;i++)
            {
                a.Add(int.Parse(jeajea1[i]));
            }
            int y = a.FindIndex(x=>x==k);
            if(y==n-1)
            {
                Console.WriteLine(a[0]);
            }
            else
            {
                Console.WriteLine(a[y+1]);
            }
        }
    }
}