n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner.

For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.


-----Input-----

The first line contains two integers: n and k (2 ≤ n ≤ 500, 2 ≤ k ≤ 10^12) — the number of people and the number of wins.

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all a_{i} are distinct.


-----Output-----

Output a single integer — power of the winner.


-----Examples-----
Input
2 2
1 2

Output
2 
Input
4 2
3 1 2 4

Output
3 
Input
6 2
6 5 3 1 2 4

Output
6 
Input
2 10000000000
2 1

Output
2



-----Note-----

Games in the second sample:

3 plays with 1. 3 wins. 1 goes to the end of the line.

3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.

Difficulty: interview

Starter code:

Solutions:
tmp = list(map(int,input().split()))
n,k = tmp[0],tmp[1]
a = list(map(int,input().split()))

cur = a[0]
w = 0
OK = False
for i in range(1,10000):
    op = a[i]
    if cur > op:
        a.append(op)
        w += 1
    else:
        cur = op
        a.append(cur)
        w = 1
    if w >= k:
        OK = True
        break
if OK:
    print(cur)
else:
    print(max(a))

n, k = list(map(int, input().split()))
if k > n:
    k = n
arr = list(map(int, input().split()))
c = 0
cur = -1
while c < k:
    if arr[0] > arr[1]:
        if cur == arr[0]:
            c += 1
        else:
            cur = arr[0]
            c = 1
        arr = [arr[0]] + arr[2:] + [arr[1]]
    else:
        if cur == arr[1]:
            c += 1
        else:
            cur = arr[1]
            c = 1
        arr = arr[1:] + [arr[0]]
print(cur)
        


import math
import re
import os
import string
import sys


def ria():
    return [int(i) for i in input().split()]


def ri():
    return int(input())


def rfa():
    return [float(i) for i in input().split()]


eps = 1e-9


def is_equal(a, b):
    return abs(a - b) <= eps


def distance(p0, p1):
    return math.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)


def distance_sqr(p0, p1):
    return (p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2


n, k = ria()
ar = ria()
mx = max(ar)
keka = 0
cur = ar[0]
mp = {}
for i in ar:
    mp[i] = 0
for i in ar:

    if cur == mx:
        print(mx)
        return

    if i == cur:
        continue
    if mp[cur] == k:
        print(cur)
        return
    if i > cur:
        mp[i] += 1
        cur = i
    else:
        mp[cur] += 1

    if mp[cur] == k:
        print(cur)
        return
    keka += 1

print(mx)

from collections import deque

n, k = list(map(int, input().split()))
a = deque(list(map(int, input().split())))
f = a.popleft()
s = a.popleft()
cnt = 0
while cnt < k:
    if f > s:
        cnt += 1
        a.append(s)
        s = a.popleft()
    else:
        cnt = 1
        a.append(f)
        f, s = s, a.popleft()
    if f == n:
        cnt = k
print(f)


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
curr_streak = 0
curr_power = a[0]
for i in range(1, n):
    if curr_power > a[i]:
        curr_streak += 1
    else:
        curr_power = a[i]
        curr_streak = 1
    if curr_streak >= k:
        print(curr_power)
        return
print(curr_power)



n, k = list(map(int, input().split()))
data = list(map(int, input().split()))
if k > 3 * n:
    print(max(data))
    return
q = data

cnt = 0
c1, c2 = q[0], q[1]
q = q[2:]

while cnt < k:
    if c1 > c2:
        cnt += 1
    else:
        c1, c2 = c2, c1
        cnt = 1
    q.append(c2)
    c2 = q[0]
    q = q[1:]
print(c1)
    


n,k = map(int, input().split())
a = list(map(int, input().split()))

if k > n:
    print(max(a))
    return

st = 0
while st < k:
    if a[0] > a[1]:
        st+=1
        a.append(a[1])
        del a[1]
    else:
        st = 1
        a.append(a[0])
        del a[0]
        
print(a[0])

(n, k) = [int(x) for x in input().split(' ')] 
a = [ int(x) for x in input().split(' ')]
if k >= 10 * (n - 1):
    print(max(a))
else:
    winner = a.pop(0)
    
    conseq_win = 0
    while conseq_win != k:
        u = winner
        v = a.pop(0)
        if u > v:
            a.append(v)
            conseq_win = conseq_win + 1
        else:
            a.append(u)
            winner = v
            conseq_win = 1
    print(winner)

def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

n, k = mi()
a = li()

from collections import deque
q = deque(a)

c = q.popleft()
w = 0
while 1:
    x = q.popleft()
    if c > x:
        w += 1
        if w >= k or w >= n:
            ans = c
            break
        q.append(x)
    else:
        q.append(c)
        c = x
        w = 1
print(ans)

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
p = a[0]
c = 0
for i in range(1, n):
    if p == n:
        print(p)
        break
    if p > a[i]:
        c += 1
        if c == k:
            print(p)
            break
    else:
        p = a[i]
        c = 1
        if p == n:
            print(p)
            break        




n, k = list(map(int, input().split()))
A = [int(x) for x in input().split()]

A.reverse()

cc = A.pop()
cr = 0

while len(A) > 0 and cc != n and cr < k:
    nc = A.pop()
    if nc > cc:
        cc = nc
        cr = 1
    else:
        cr += 1

print(cc)


n,k=list(map(int,input().split()))
ar=list(map(int,input().split()))
mx=max(ar)
winns={x:0 for x in ar}
while True:
    if ar[0] > ar[1]:
        if(ar[0]==mx or winns[ar[0]] >= k-1):
            print(ar[0])
            break
        ar.append(ar.pop(1))
        
    else:
        ar.append(ar.pop(0))
    winns[ar[0]]+=1
    #print(ar)


n, needed = map(int, input().split())
players = list(map(int, input().split()))

winner = players[0]
wins = 0

for i in range(1, n):
    if players[i] > winner:
        winner = players[i]
        wins = 1
    else:
        wins += 1
    if wins >= needed:
        break
    
print(winner)

read = lambda: tuple(map(int, input().split()))


def main():
    n, k = read()
    l = list(read())

    ps = {}
    def add(p):
        if not p in ps:
            ps[p] = 1
        else:
            ps[p] += 1
        return (ps[p] >= k, p)
    newl = []
    while(len(l) > 1):
        v1, v2 = l[0], l[1]
        if v1 > v2:
            l.pop(1)
            newl += [v2]
            addk = add(v1)
        else:
            l.pop(0)
            newl += [v1]
            addk = add(v2)
        if addk[0]:
            return addk[1]
    return l[0]
print(main())


def solve():
    from collections import deque
    N, K = map(int, input().split())
    dq = deque((map(int, input().split())))
    popleft, append = dq.popleft, dq.append
    win = 0
    cur = popleft()
    while dq:
        vs = popleft()
        if cur > vs:
            win += 1
            append(vs)
        else:
            win = 1
            append(cur)
            cur = vs
        if win == K or win > N:
            print(cur)
            break


def __starting_point():
    solve()
__starting_point()

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
maxa = max(a)
if len(a) <= k:
    print(maxa)
else:
    curr = a[0]
    j = 0
    for i in range(1, len(a)):
        if j == k:
            print(curr)
            break
        if a[i] == maxa:
            print(maxa)
            break
        if a[i] > curr:
            curr = a[i]
            j = 1
        else:
            j += 1


n,k=list(map(int,input().split()))
l=list(map(int,input().split()))
maxi=max(l)
a=max(l[:2])
b=min(l[:2])
l=l[2:]
g=k
while g:
    if a==maxi:
        break
    if a>b:
        g-=1
        l.append(b)
        b=l[0]
        del l[0]
    elif b>a:
        g=k-1
        l.append(a)
        a=b
        b=l[0]
        del l[0]
print(a)

a=input().split(' ')
n=int(a[0])
k=int(a[1])
a=input().split(' ')
a=[int(i) for i in a]
if k>n-1:
    print(max(a))
    return
wf=0
c=0
cw=a[0]
for i in range(1,n-1):
    cw=max(cw,a[i])
    if a[i]==cw:
        c=1
        continue
    c=c+1
    if c>=k:
        wf=cw
        print(wf)
        break
else:
    print(max(a))


n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
p=max(a)
t=0
if k>600:
    print(p)
else:
    while t!=k:
        if a[0]>a[1]:
            if a[0]==p:
                print(p)
                return
            m=a[1]
            del a[1]
            a.append(m)
            t+=1
        else:
            m=a[0]
            del a[0]
            a.append(m)
            t=1
    print(a[0])
    


# python3
# utf-8

players_nr, max_win_streak = (int(x) for x in input().split())
player_idx___power = [int(x) for x in input().split()]
if max_win_streak > players_nr:
    print(max(player_idx___power))
    quit()
curr_win_streak = 0
curr_power = player_idx___power[0]
next_player_idx = 1
while curr_win_streak < max_win_streak:
    next_power = player_idx___power[next_player_idx]
    if curr_power < next_power:
        curr_power = next_power
        player_idx___power.append(curr_power)
        curr_win_streak = 1
    else:
        player_idx___power.append(next_power)
        curr_win_streak += 1
    next_player_idx += 1
print(curr_power)


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

ans = max(a)
tmp = a[0]
cnt = 0
for i in range(1, n):
    if tmp < a[i]:
        tmp = a[i]
        cnt = 1
    else:
        cnt += 1
    if cnt == k:
        ans = tmp
        break
print(ans)


# your code goes here
n,k = input().split()
n=int(n)
k=int(k)
a = list(map(int,input().split()))
count=0
i=0
j=1
while True:
	if(k>n):
		print(max(a))
		break
	if(a[i]>a[j]):
		count+=1
		if(count==k):
			print(a[i])
			break
		a.append(a[j])
		a.remove(a[j])
	else:
		a.append(a[i])
		a.remove(a[i])
		count=1


n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
max1=max(a)
b=[]
done=False
for i in range(n):
    b.append(0)
m=a.index(max1)
if(k>m):
    print(max1)
else:
    curr=0
    for i in range(1,m):
        if(a[curr]>a[i]):
            #print(b)
            b[curr]+=1
        else:
            curr=i
            b[curr]+=1
        if(max(b)>=k):
            done=True
            print(a[b.index(max(b))])
            break
    if(not done):
        print(max1)


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
maxa = max(a)
if len(a) <= k:
    print(maxa)
else:
    qq = a[0]
    j = 0
    for i in range(1, len(a)):
        if j == k:
            print(qq)
            break
        if a[i] == maxa:
            print(maxa)
            break
        if a[i] > qq:
            qq = a[i]
            j = 1
        else:
            j += 1


n, k = list(map(int, input().split()))
powers = list(map(int, input().split()))[:n]

if k >= n - 1:
	print(max(powers))
else:
	wins = 0
	index = 0
	while True:
		A = index % n
		B = (index + 1) % n
		winner_power = -1
		if powers[A] < powers[B]:
			winner_power = powers[B]
			wins = 1
		else:
			winner_power = powers[A]
			powers[A], powers[B] = powers[B], powers[A]
			wins += 1
		index = B

		if wins >= k:
			print(winner_power)
			break