using System;
using System.Collections.Generic;

namespace Madionicar
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            List<int> a = new List<int>();
            string [] m= Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a.Add(int.Parse(m[i]));
            }
            string l = Console.ReadLine();
            if (l=="ne")
            {
                int c = a.FindIndex(x=>(x==k));
                Console.WriteLine(a[c+1]);
            }
            else
            {
                if (l=="da")
                {
                    int c = a.FindIndex(x => (x == k));
                    if (c+1 == a.Count)
                    {
                        Console.WriteLine(a[0]);
                    }
                    else
                    {
                        Console.WriteLine(a[c + 1]);
                    }
                }
            }
        }
    }
}