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: EASY

Solutions:
(n, k) = map(int, input().split())
a = [*map(int, input().split())]
current = 0
ans = a[0]
i = 1
while i < n:
	if ans > a[i]:
		current += 1
	else:
		current = 1
		ans = a[i]
	if current == k:
		break
	i += 1
print(ans)


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

def sila_v_igroka(mas, k):
	x = 0
	sila = 0
	if len(mas) <= k:
		return max(mas)
	while x != k:
		if mas[0] > mas[1]:
			sila = mas[0]
			mas = [mas[0]] + mas[2:] + [mas[1]]
			x += 1
		else:
			mas = [mas[1]] + mas[2:] + [mas[0]]
			sila = mas[0]
			x = 1
		if x == k:
			break
	return sila
print(sila_v_igroka(massiv, k))


def main():
	(n, k) = map(int, input().split())
	power = list(map(int, input().split()))
	cnt = 0
	win = power[0]
	del power[0]
	while True:
		for i in range(0, len(power)):
			if win > power[i]:
				cnt = cnt + 1
				if cnt >= len(power):
					print(win)
					return
				if cnt >= k:
					print(win)
					return
			else:
				for j in range(0, i):
					power.append(power[0])
					del power[0]
				power.append(win)
				win = power[0]
				del power[0]
				cnt = 1
				break
main()


from collections import deque

def simu(k, A):
	M = max(A)
	v = 0
	while A[0] < M and v < k:
		if A[0] > A[1]:
			v += 1
			A.append(A[1])
			A[1] = A[0]
		else:
			v = 1
			A.append(A[0])
		A.popleft()
	return A[0]

def main():
	(n, k) = map(int, input().split())
	A = deque(map(int, input().split()))
	print(simu(k, A))
main()


(tamanho, quantidades_vit) = map(int, input().split())
desafiantes = list(map(int, input().split()))
maior = max(desafiantes)
if quantidades_vit >= tamanho:
	print(maior)
else:
	vencedor_atual = None
	cont = 0
	while True:
		if cont >= quantidades_vit or vencedor_atual == maior:
			print(vencedor_atual)
			break
		vencedor_anterior = vencedor_atual
		if desafiantes[0] > desafiantes[1]:
			perdedor = desafiantes.pop(1)
			desafiantes.append(perdedor)
			vencedor_atual = desafiantes[0]
			cont += 1
		else:
			perdedor = desafiantes.pop(0)
			desafiantes.append(perdedor)
			vencedor_atual = desafiantes[1]
			cont = 1


b = list(map(int, input().split()))
a = list(map(int, input().split()))
n = b[0]
k = b[1]
l = 0
p = 0
q = 1
while 1:
	if q % n == 0:
		q = 0
	if a[p] >= a[q]:
		if a[p] != a[q]:
			l += 1
		if l % n == 0 or l == k:
			print(a[p])
			break
	else:
		p += 1
		q = p
		l = 1
	q += 1


inp = lambda : map(int, input().split())
(n, k) = inp()
a = list(inp())
if k > n:
	print(max(a))
	quit()
line = [0] * 501
win = [0] * 501
for i in range(n):
	line[i] = i
max_win = 0
for i in range(n + k + 2):
	if a[line[0]] > a[line[1]]:
		win[line[0]] += 1
		if win[line[0]] > max_win:
			max_win = win[line[0]]
		if max_win >= k:
			print(a[line[0]])
			quit()
		x = line[1]
		for j in range(1, n - 1):
			line[j] = line[j + 1]
		line[n - 1] = x
	else:
		win[line[1]] += 1
		if win[line[0]] > max_win:
			max_win = win[line[1]]
		if max_win >= k:
			print(a[line[1]])
			quit()
		x = line[0]
		for j in range(0, n - 1):
			line[j] = line[j + 1]
		line[n - 1] = x


def pingpong(n, k):
	power = [int(i) for i in input().split()]
	wins = 0
	for i in range(1, n):
		if wins >= k:
			return power[0]
		elif power[0] > power[i]:
			wins += 1
		else:
			wins = 1
			power[0] = power[i]
	return power[0]
(n, k) = map(int, input().split())
print(pingpong(n, k))


from collections import deque
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if n == 2:
	print(max(arr))
	exit()
for i in range(n):
	var = i + k
	if i == 0:
		if var >= n:
			if arr[i] >= max(arr[i:n]) and arr[i] >= max(arr[:k - (n - i - 1) + 1]):
				print(arr[i])
				break
		elif arr[i] >= max(arr[i:i + k + 1]):
			print(arr[i])
			break
	elif var >= n:
		if arr[i] >= max(arr[i - 1:n]) and arr[i] >= max(arr[:k - (n - i - 1)]):
			print(arr[i])
			break
	elif arr[i] >= max(arr[i - 1:i + k]):
		print(arr[i])
		break


(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)


def queue(list_, k):
	wins = 0
	while wins < k:
		if int(list_[0]) > int(list_[1]):
			index = 1
			wins += 1
		else:
			index = 0
			wins = 1
		list_.append(list_[index])
		list_.pop(index)
	return list_[0]
first = input().split()
k = int(first[1])
list_ = input().split()
if k > len(list_) - 1:
	k = len(list_) - 1
print(queue(list_, k))


def main():
	import collections
	(n, k) = map(int, input().split())
	k = min(n, k)
	dq = collections.deque(map(int, input().split()))
	best = dq.popleft()
	streak = 0
	while streak < k:
		opp = dq.popleft()
		if best > opp:
			dq.append(opp)
			streak += 1
		else:
			dq.append(best)
			best = opp
			streak = 1
	print(best)
try:
	while True:
		main()
except EOFError:
	pass


import math
import os
import random
import re
import sys
playerAndWins = input().split()
noOfPlayers = int(playerAndWins[0])
noOfWins = int(playerAndWins[1])
playerPower = list(map(int, input().rstrip().split()[:noOfPlayers]))
i = 0
checker = []
if noOfWins > 1000:
	noOfWins = 1000
while len(checker) < noOfWins:
	if playerPower[i] > playerPower[i + 1]:
		checker.append(playerPower[i + 1])
		playerPower.append(playerPower[i + 1])
		del playerPower[i + 1]
	elif playerPower[i] < playerPower[i + 1]:
		playerPower.append(playerPower[i])
		del playerPower[i]
		checker.clear()
		checker.append(playerPower[i + 1])
print(playerPower[i])


s = input().split()
n = int(s[0])
k = float(s[1])
s = input().split()
i = 0
a = []
while i < n:
	a.append(int(s[i]))
	i += 1
p = 0
t = a.index(n)
if k < t:
	while p < k:
		if a[0] == n:
			break
		if a[0] > a[1]:
			p += 1
			if p == k:
				break
			a.append(a[1])
			a.pop(1)
		else:
			p = 1
			a.append(a[0])
			a.pop(0)
	print(a[0])
else:
	print(n)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
s = 0
e = 0
f = 1
if k >= n - 1:
	e = max(a)
else:
	while s < k:
		if a[0] > a[1] and f != 1:
			s += 1
			c = a[1]
			del a[1]
			a.append(c)
		elif f == 1:
			s += 1
			c = max(a[0], a[1])
			d = min(a[0], a[1])
			del a[0]
			del a[0]
			a.insert(0, c)
			a.append(d)
		else:
			s = 1
			c = a[0]
			del a[0]
			a.append(c)
		f -= 1
	e = a[0]
print(e)


(n, k) = (int(x) for x in list(input().split(' ')))
players = list(map(int, input().split()))
if k > 500:
	print(max(players))
else:
	win = 0
	while win < k:
		if int(players[0]) > int(players[1]):
			players.append(players.pop(1))
			win += 1
		else:
			win = 0
			players.append(players.pop(0))
			win += 1
	print(players[0])


from collections import deque
(n, k) = map(int, input().split())
a = deque(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)


while True:
	try:
		(n, k) = map(int, input().split())
		a = input().split()
		ans = int(a[0])
		st = 0
		for i in range(1, n):
			if st >= k:
				break
			if ans > int(a[i]):
				st += 1
			else:
				st = 1
				ans = int(a[i])
		print(ans)
	except EOFError:
		break


from sys import stdout, stdin

def play(line, n, k):
	player1 = line[0]
	player2 = 0
	wins = 0
	i = 1
	while i < len(line):
		player2 = line[i]
		if player1 > player2:
			wins += 1
		else:
			player1 = player2
			wins = 1
		if wins == k:
			i = len(line)
		i += 1
	return player1
line = stdin.readline().replace('\n', '').split(' ')
(n, k) = (int(line[0]), int(line[1]))
people = [int(x) for x in stdin.readline().replace('\n', '').split(' ')]
print(play(people, n, k))


pV = input().split()
p = int(pV[0])
vNeeded = int(pV[1])
powP = list(map(int, input().rstrip().split()))
if p < vNeeded:
	print(max(powP))
else:
	win = 0
	while win < vNeeded:
		if int(powP[0]) > int(powP[1]):
			powP.append(powP.pop(1))
			win = win + 1
		else:
			win = 0
			powP.append(powP.pop(0))
			win = win + 1
	print(powP[0])


def tableTennis(n, k, powers):
	players = powers
	tempWinners = []
	if len(powers) == 2:
		if powers[0] > powers[1]:
			return powers[0]
		else:
			return powers[1]
	if k > len(powers):
		return max(powers)
	while len(tempWinners) < k:
		challenger = players.pop(0) if not tempWinners else tempWinners[-1]
		if challenger > players[0]:
			tempWinners.append(challenger)
			players.append(players.pop(0))
		else:
			if tempWinners:
				tempWinners.clear()
			players.append(challenger)
			tempWinners.append(players.pop(0))
	return tempWinners[-1]
(n, k) = list(map(int, input().rstrip().split()))
powers = list(map(int, input().rstrip().split()))
print(tableTennis(n, k, powers))


(size, totalwins) = [int(x) for x in input().split()]
line = [int(x) for x in input().split()]
players = list(line)
champ = line.pop(0)
wins = 0
for x in range(size - 1):
	newbie = line.pop(0)
	if champ > newbie:
		wins += 1
	else:
		champ = newbie
		wins = 1
	if wins == totalwins:
		break
if line:
	print(champ)
else:
	print(max(players))


(n, k) = map(int, input().split())
(a, i, v, c) = (list(map(int, input().split())), 0, 0, 0)
while v < n and c < k:
	(w, l) = (max(a[i], a[i + 1]), min(a[i], a[i + 1]))
	a[i + 1] = w
	a.append(l)
	c = c + 1 if w == v else 1
	v = w
	i += 1
print(v)


from queue import deque
(n, k) = map(int, input().split())
(m, *l) = map(int, input().split())
(q, c) = (deque(l), 0)
while m < n:
	a = q.popleft()
	if m < a:
		q.append(m)
		(m, c) = (a, 1)
	else:
		q.append(a)
		c += 1
		if c == k:
			break
print(m)


from collections import deque
(n, k) = map(int, input().split())
arr = deque(list(map(int, input().split())))
major = arr.popleft()
cnt = 0
while cnt < min(k, n):
	item = arr.popleft()
	if item < major:
		arr.append(item)
		cnt += 1
	else:
		cnt = 1
		arr.append(major)
		major = item
print(major)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
p = list(map(int, stdin.readline().split()))
if k >= n - 1:
	p.sort(reverse=True)
	stdout.write(str(p[0]))
else:
	n1 = p[0]
	del p[0]
	c = 0
	for item in p:
		if item > n1:
			n1 = item
			c = 1
		else:
			c = c + 1
			if c == k:
				break
	stdout.write(str(n1))


(n, k) = map(int, input().split())
if k > 5000:
	k = 5000
lst = []
for x in input().split():
	lst.append(int(x))
s = []
d = {}
win = max(lst[0], lst[1])
out = min(lst[0], lst[1])
lst.remove(out)
lst.append(out)
s.append(win)
d[win] = 1
acc = 0
while acc != k:
	win = max(s[-1], lst[1])
	out = min(s[-1], lst[1])
	lst.remove(out)
	lst.append(out)
	s.append(win)
	if not win in d:
		d[win] = 0
	d[win] += 1
	acc = max(d.values())
print(max(d))


(n, k) = map(int, input().split())
v = list(map(int, input().split()))
count = 0
previous = v[0]
for i in range(1, n):
	if previous > v[i]:
		count += 1
	else:
		previous = v[i]
		count = 1
	if count == k:
		break
print(previous)


firstInput = input().split(' ')
numberPlayers = int(firstInput[0])
numberWinsNecessary = int(firstInput[1])
powerPlayers = []
secondInput = input().split(' ')
for i in range(numberPlayers):
	powerPlayers.append(int(secondInput[i]))
lastWinner = powerPlayers[0]
wins = 0
while wins < numberWinsNecessary and len(powerPlayers) > 1:
	if lastWinner > powerPlayers[1]:
		powerPlayers.pop(1)
		wins += 1
	else:
		powerPlayers[0] = powerPlayers[1]
		powerPlayers.pop(1)
		lastWinner = powerPlayers[0]
		wins = 1
print(lastWinner)


(number_of_players, win_requirement) = input().split()
number_of_players = int(number_of_players)
win_requirement = int(win_requirement)
powers = input().split(' ')
powers = [int(power) for power in powers]
if powers[0] > max(powers[1:min(number_of_players, win_requirement + 1)]):
	print(powers[0])
else:
	powers = powers[1:] + [powers[0]]
	for i in range(number_of_players - 1):
		if powers[0] > max(powers[1:min(number_of_players, win_requirement)]):
			print(powers[0])
			break
		else:
			powers = powers[1:] + [powers[0]]


from collections import deque
(n, k) = map(int, input().split())
guys = [int(x) for x in input().split()]
wins = dict()
queue = deque()
max_power = max(guys)
for guy in guys:
	wins[guy] = 0
	queue.append(guy)
cur = guys[0]
queue.popleft()
while cur != max_power and wins[cur] != k:
	enemy = queue.popleft()
	if enemy > cur:
		(cur, enemy) = (enemy, cur)
	wins[cur] += 1
	queue.append(enemy)
print(cur)


(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])


from collections import deque
(n, k) = map(int, input().split())
num = list(map(int, input().split()))
q = deque()
kolvo = 0
fl = False
wins = [0] * n
for i in range(2, len(num)):
	q.append(num[i])
battle = [num[0], num[1]]
while not k in wins and (not fl):
	x = min(battle)
	pr = max(battle)
	pr1 = max(battle)
	if kolvo > 1:
		if pr1 != pr:
			wins[pr - 1] = 0
		if wins[pr - 1] > len(num):
			print(pr)
			fl = True
			break
	battle.pop(battle.index(x))
	q.append(x)
	y = q.popleft()
	battle.append(y)
	kolvo += 1
	wins[pr - 1] += 1
if not fl:
	print(pr)


(n, k) = map(int, input().split())
power = list(map(int, input().split()))
results = {i: 0 for i in range(n)}
maximal = max(power)
max_index = power.index(maximal)
for i in range(max_index):
	if power[i] < power[i + 1]:
		results[i + 1] += 1
	ind = i + 1
	while power[ind] < power[i]:
		results[i] += 1
		ind += 1
	if results[i] >= k:
		print(power[i])
		exit(0)
print(maximal)


from collections import deque
inp = lambda : map(int, input().split())
(n, k) = inp()
player = deque(list(inp()))
win = 0
while win < k:
	if player[0] > player[1]:
		win += 1
		winner = player.popleft()
		loser = player.popleft()
		player.appendleft(winner)
		player.append(loser)
	else:
		win = 1
		loser = player.popleft()
		player.append(loser)
	if win >= n:
		break
print(player[0])


(numero_de_pessoas, vitorias_nescessarias) = map(int, input().split(' '))
fila = list(map(int, input().split(' ')))
jogador_1 = fila.pop(0)
jogador_2 = fila.pop(0)
jogador_ganhando = -1
pontos = 0
while pontos < vitorias_nescessarias:
	if jogador_1 > jogador_2:
		if jogador_1 == jogador_ganhando:
			pontos += 1
		else:
			pontos = 1
			jogador_ganhando = jogador_1
		if len(fila) > 0:
			jogador_2 = fila.pop(0)
		else:
			break
	else:
		if jogador_2 == jogador_ganhando:
			pontos += 1
		else:
			pontos = 1
			jogador_ganhando = jogador_2
		if len(fila) > 0:
			jogador_1 = fila.pop(0)
		else:
			break
print(jogador_ganhando)


first = input().split()
second = input().split()
intFirst = []
for x in first:
	intFirst.append(int(x))
intSecond = []
for y in second:
	intSecond.append(int(y))
numberPlayers = intFirst[0]
wins = intFirst[1]
counter = 0
winner = 0
realWinner = 0
if numberPlayers < wins:
	print(max(intSecond))
else:
	while counter < wins:
		realWinner = 0
		if intSecond[0] > intSecond[1]:
			realWinner = intSecond[0]
			intSecond.append(intSecond[1])
			intSecond.pop(1)
		else:
			realWinner = intSecond[1]
			intSecond.append(intSecond[0])
			intSecond.pop(0)
		if realWinner == winner:
			counter = counter + 1
		else:
			winner = realWinner
			counter = 1
	print(winner)


def solve(a, k):
	co = 0
	x = []
	if k < len(a):
		while co < k:
			if a[0] > a[1]:
				te = a[1]
				del a[1]
				a.append(te)
			else:
				te = a[0]
				del a[0]
				a.append(te)
			x.append(a[0])
			if len(x) == 1:
				co += 1
				answer = x[-1]
			elif x[-1] == x[-2]:
				co += 1
				answer = x[-1]
			else:
				co = 1
				answer = x[-1]
		return answer
	else:
		return max(a)
(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
x = solve(l, k)
print(x)


(n, k) = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
win = p[0]
count = 1
for i in range(1, len(p)):
	if win < p[i]:
		win = p[i]
		count = 2
	elif win > p[i] and count == k:
		print(win)
		break
	else:
		count = count + 1
else:
	print(win)


s = input().split()
n = int(s[0])
k = int(s[1])
a = [int(i) for i in input().split()]
powerfull = a[0]
key = 0
if k > n:
	print(max(a))
else:
	while key < k:
		if a[0] > a[1]:
			key += 1
			for i in range(1, n - 1):
				(a[i], a[i + 1]) = (a[i + 1], a[i])
		if a[0] < a[1] and k != key:
			for i in range(n - 1):
				(a[i], a[i + 1]) = (a[i + 1], a[i])
			key = 1
			powerfull = a[0]
	print(powerfull)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
high = max(a.pop(0), a.pop(0))
if n == 2:
	run = False
else:
	run = True
try:
	while run:
		for i in range(k - 1):
			if a[i] > high:
				high = a[i]
				a = a[i + 1:]
				break
			elif i + 2 == k:
				run = False
				break
except IndexError:
	pass
print(high)


(size, req_Wins) = [int(x) for x in input().split()]
queue = [int(x) for x in input().split()]
players = list(queue)
undefeated = queue.pop(0)
wins = 0
for x in range(size - 1):
	challenger = queue.pop(0)
	if undefeated > challenger:
		wins += 1
	else:
		undefeated = challenger
		wins = 1
	if wins == req_Wins:
		break
if queue:
	print(undefeated)
else:
	print(max(players))


(n, k) = map(int, input().rstrip().split(' '))
players = list(map(int, input().rstrip().split(' ')))
if n <= k:
	k = n - 1
winner = 0
winCount = 0
for i in range(1, n):
	tempComp = max(players[i], players[winner])
	if players[winner] == tempComp:
		winCount += 1
	else:
		winCount = 1
		winner = i
	if winCount == k:
		break
print(players[winner])


from collections import deque

def ping_pong(wins, players):
	p = deque(players)
	i = 0
	while i < len(p):
		wcounter = 0
		has_fought = []
		fcounter = 0
		while True:
			fcounter += 1
			if p[0] > p[1]:
				if fcounter == 1 and p[0] > p[-1]:
					wcounter += 2
				else:
					wcounter += 1
				has_fought.append(p[1])
				if wcounter == wins or (len(has_fought) + 1 == len(p) and max(p) == p[0]):
					print(p[0])
					return
				else:
					temp = p[1]
					p.remove(temp)
					p.append(temp)
			else:
				val = p.popleft()
				p.append(val)
				break
		i += 1

def main():
	first_line = [int(x) for x in input().split(' ')]
	second_line = [int(x) for x in input().split(' ')]
	ping_pong(first_line[1], second_line)
main()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
if k >= n:
	print(sorted(l)[-1])
else:
	while c < k:
		if l[0] > l[1]:
			c = c + 1
			l.insert(n, l[1])
			del l[1]
		else:
			c = 1
			l.insert(n, l[0])
			del l[0]
	print(l[0])


from collections import deque
from collections import defaultdict
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
maxo = max(a)
if a.index(maxo) == 0:
	print(maxo)
elif n == 2:
	print(maxo)
elif k > n:
	print(maxo)
elif k <= n:
	di = defaultdict(int)
	ans = 0
	que = a
	while True:
		x = a[0]
		y = a[1]
		que.pop(0)
		que.pop(0)
		que.insert(0, max(x, y))
		que.append(min(x, y))
		di[max(x, y)] += 1
		if di[max(x, y)] == k:
			ans = max(x, y)
			break
	print(ans)


(p, n) = map(int, input().split())
strength = list(map(int, input().split()))
if n >= p:
	print(max(strength))
else:
	curmax = strength[0]
	curn = 0
	for i in range(1, p):
		if strength[i] > curmax:
			curmax = strength[i]
			curn = 1
		else:
			curn += 1
			if curn >= n:
				print(curmax)
				curn = -1
				break
	if curn >= 0:
		print(curmax)


(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


entrada = list(map(int, input().split()))
jogo = list(map(int, input().split()))
i = jogo[0]
j = 1
temp = 0
vitorias = 0
cond = True
if entrada[1] >= max(jogo):
	temp = max(jogo)
	cond = False
jogo.append('X')
while cond:
	if vitorias >= entrada[1] or jogo[j] == 'X':
		break
	elif i > jogo[j]:
		vitorias += 1
		j += 1
	else:
		i = jogo[j]
		j += 1
		vitorias = 1
	temp = i
print(temp)


(n, k) = list(map(int, input().split()))
powers = list(map(int, input().split()))
current_streak = 0
if k > n - 1:
	print(max(powers))
	exit(0)
while True:
	if powers[0] > powers[1]:
		current_streak += 1
		temp = powers.pop(1)
		powers.append(temp)
	else:
		current_streak = 1
		temp = powers.pop(0)
		powers.append(temp)
	if current_streak == k:
		break
print(powers[0])


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

class Queue:

	def __init__(self):
		self.items = []

	def enqueue(self, item):
		self.items.append(item)

	def insrt(self, item):
		self.items.insert(0, item)

	def dequeue(self):
		return self.items.pop(0)

	def is_empty(self):
		if self.items == []:
			return True
		return False

	def check(self, i):
		if l[i] == max(l):
			return True
		return False
s = 0
save = -1
q = Queue()
for i in l:
	q.enqueue(i)
if k <= n:
	while s < k:
		a = q.dequeue()
		b = q.dequeue()
		if a > b:
			q.insrt(a)
			q.enqueue(b)
			if save == a:
				s += 1
			else:
				save = a
				s = 1
		else:
			q.insrt(b)
			q.enqueue(a)
			if save == b:
				s += 1
			else:
				save = b
				s = 1
else:
	for i in range(n):
		check = q.check(i)
		if check == 1:
			save = l[i]
			break
print(save)


firstGiven = input().split()
testCase = int(firstGiven[0])
players = input().split()
activePlayerOne = int(players[0])
activePlayerTwo = int(players[1])
playerOneWins = -1
playerTwoWins = -1
winCondition = 0
MVP = 0
for x in players:
	player = int(x)
	if MVP < player:
		MVP = player
if int(firstGiven[1]) >= testCase:
	winCondition = 0
	activePlayerOne = MVP
else:
	winCondition = int(firstGiven[1])
	if winCondition >= testCase and len(players) > 2:
		activePlayerOne == MVP
		playerOneWins == winCondition
playerOneWins = 0
playerTwoWins = 0
if len(players) == 2:
	if activePlayerOne > activePlayerTwo:
		playerOneWins = winCondition
	else:
		playerTwoWins = winCondition
while playerOneWins != winCondition and playerTwoWins != winCondition:
	if activePlayerOne > activePlayerTwo:
		players.append(str(activePlayerTwo))
		players.remove(str(activePlayerTwo))
		activePlayerTwo = int(players[1])
		playerTwoWins = 0
		playerOneWins += 1
	else:
		players.append(str(activePlayerOne))
		players.remove(str(activePlayerOne))
		activePlayerOne = int(players[1])
		playerOneWins = 0
		playerTwoWins += 1
if playerOneWins == winCondition:
	print(activePlayerOne)
elif playerTwoWins == winCondition:
	print(activePlayerTwo)


def main():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	res = 0
	count = 0
	if n < k:
		res = max(l)
	else:
		while count != k:
			if l[0] > l[1]:
				count += 1
				l = swap(l, 1)
			else:
				count = 1
				l = swap(l, 0)
		res = l[0]
	print(res)

def swap(l, i):
	tmp = l[i]
	l.pop(i)
	l.append(tmp)
	return l
main()


(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]:
			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)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = list(map(int, input().rstrip().split()))
winner = 0
if k > n:
	winner = max(a)
else:
	q = []
	for i in a:
		q.append(i)
	wins = 0
	winner = q[0]
	q.pop(0)
	while wins != k:
		front = q[0]
		if winner > front:
			wins = wins + 1
			q.append(front)
			q.pop(0)
		else:
			wins = 1
			q.append(winner)
			winner = q[0]
			q.pop(0)
print(winner)


from collections import deque
(n, k) = [int(p) for p in input().split()]
q = deque([int(p) for p in input().split()])
curr = q[0]
count = 0
while k > count:
	p1 = q.popleft()
	p2 = q.popleft()
	win = max(p1, p2)
	los = min(p1, p2)
	if win == curr:
		count += 1
	else:
		curr = win
		count = 1
	q.append(los)
	q.appendleft(win)
	if win == n:
		break
print(win)


from queue import Queue
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = Queue()
for aa in a:
	q.put(aa)
cur = q.get()
sec = q.get()
if cur > sec:
	q.put(sec)
else:
	q.put(cur)
	cur = sec
while 1:
	wins = 1
	sec = q.get()
	while sec < cur:
		wins += 1
		q.put(sec)
		if wins > n or wins == k:
			print(cur)
			exit(0)
		sec = q.get()
	q.put(cur)
	cur = sec


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
if k > n - 1:
	print(max(a))
else:
	count = 0
	i = 0
	j = 1
	found = False
	while i < n and j < n:
		if a[i] > a[j]:
			count += 1
			j += 1
		else:
			count = 1
			i = j
			j += 1
		if count == k:
			found = True
			break
	if found:
		print(a[i])
	else:
		print(max(a))


(n, k) = 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


def solve(n, k, a):
	big = max(a)
	win_c = 0
	for i in range(n):
		if a[i] == big:
			return big
		for j in range(i + 1, n):
			if a[i] > a[j]:
				win_c += 1
			else:
				win_c = 1
				break
			if win_c == k:
				return a[i]
tmp = input().split()
n = int(tmp[0])
k = int(tmp[1])
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
res = solve(n, k, a)
print(res)


[n, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
wins = [0 for i in range(n + 1)]
if k < 1000:
	while True:
		x = a[0]
		y = a[1]
		if x > y:
			a.remove(y)
			a.append(y)
			wins[x] += 1
			if wins[x] == k:
				print(x)
				exit(0)
		else:
			a.remove(x)
			a.append(x)
			wins[y] += 1
			if wins[y] == k:
				print(y)
				exit(0)
amax = max(a)
print(amax)


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
(i, cnt, ans) = (0, 0, 0)
while i < n and cnt < k:
	if ans:
		if ans > arr[i]:
			cnt += 1
		else:
			cnt = 1
	else:
		cnt = 0
	ans = max([ans, arr[i]])
	i += 1
print(ans)


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
power = powers[0]
wins = 0
for i in range(1, n):
	if power > powers[i]:
		wins += 1
	else:
		wins = 1
		power = powers[i]
	if wins >= k:
		break
print(power)


def tabletennis(n, cP):
	st = 0
	for i in range(1, p):
		if st == nOW:
			return cP
		elif cP > n[i]:
			st += 1
		else:
			cP = n[i]
			st = 1
	return cP
(p, nOW) = map(int, input().split())
n = input().split()
n = list(map(int, n))
cP = n[0]
print(tabletennis(n, cP))


(n, k) = [int(x) for x in input().split()]
power = [int(x) for x in input().split()]
i = 0
if k >= n:
	print(max(power))
else:
	while i < n:
		(flag, flag2) = (0, 0)
		if i == 0:
			withPlayers = i + k + 1
		else:
			withPlayers = i + k
		for j in range(i + 1, withPlayers):
			if j == n:
				print(power[tempWinner])
				flag2 = 1
				break
			if power[j] > power[i]:
				(i, flag) = (j, 1)
				tempWinner = i
				break
		if j == withPlayers - 1 and flag == 0:
			if not flag2:
				print(power[i])
			flag2 = 1
			break
		if flag == 0:
			i += 1
		if flag2:
			break
	if flag2 == 0:
		print(power[tempWinner])


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
if n <= k:
	print(max(p))
else:
	i = 0
	ans = 0
	while i < n:
		j = i + 1
		fl = False
		tot = 0
		if i > 0:
			tot = 1
		if j < n:
			while p[i] > p[j] and j + 1 < n:
				j += 1
				tot += 1
				fl = True
		if tot >= k and fl:
			print(p[i])
			exit(0)
		i = max(j, i + 1)
	print(max(p))


inp = input()
inp = inp.split()
n = int(inp[0])
k = int(inp[1])
d = input()
d = d.split()
d = [int(d[x]) for x in range(n)]
tot = [0 for _ in range(505)]
i = 0
ans = d[0]
for i in range(1, n):
	if ans > d[i]:
		tot[ans] += 1
	else:
		(ans, d[i]) = (d[i], ans)
		tot[ans] += 1
	if tot[ans] == k:
		print(ans)
		exit(0)
print(ans)


(n, k) = map(int, input().split())
q = list(map(int, input().split()))
mx = max(q)
if k >= n - 1:
	print(mx)
else:
	i = 0
	x = 0
	f = False
	for r in range(1, n - 1):
		if q[r] > q[i]:
			i = r
			x = 1
		else:
			x += 1
		if x == k:
			f = True
			print(q[i])
			break
	if not f:
		print(mx)


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
r = z.index(max(z))
j = 0
i = 0
while i < r:
	s = 0
	if i != 0:
		if z[i - 1] < z[i]:
			s += 1
	for j in range(i + 1, r):
		if z[i] > z[j]:
			s += 1
		else:
			break
	if s >= b:
		exit(print(z[i]))
	i = max(i + 1, j)
print(max(z))


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
solve()


from collections import deque
(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
cont = 0
x = deque(l)
j = l[0]
x.popleft()
x_init = x
flag = 0
if k > n - 1:
	print(max(l))
	exit()
while cont != k:
	if j > x[0]:
		cont += 1
		r = x.popleft()
		x.append(r)
	else:
		cont = 1
		x.append(j)
		j = x.popleft()
print(j)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
maximum = max(a)
winner = count = 0
while count < k:
	cur = a[0]
	if cur == maximum:
		winner = cur
		break
	next = a[1]
	if next == maximum:
		winner = next
		break
	if cur > next:
		winner = cur
		a = [cur] + a[2:] + [next]
		count += 1
	else:
		a = a[1:] + [cur]
		count = 1
print(winner)


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
max_power = max(powers)

def get_winner():
	i = 0
	size = len(powers)
	extra = 1
	while True:
		if powers[i] == max_power:
			return powers[i]
		for j in range(i + 1, min(i + k + extra, size)):
			if powers[i] < powers[j]:
				extra = 0
				i = j
				break
		else:
			return powers[i]
print(get_winner())


import queue
import sys
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
if n == 2:
	print(2)
	sys.exit(0)
q = queue.Queue()
maxi = max(ar)
for i in ar:
	q.put(i)
wins = 0
a = q.get()
if a == maxi:
	print(a)
	sys.exit(0)
while True:
	b = q.get()
	if b == maxi:
		print(b)
		sys.exit(0)
	if b > a:
		q.put(a)
		a = b
		wins = 1
	else:
		wins += 1
		q.put(b)
	if wins >= k:
		print(a)
		sys.exit(0)


(n, k) = 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)
		exit()
print(curr_power)


first = input()
(n, k) = [int(x) for x in first.split()]
n = int(n)
k = int(k)
second = input()
nums = [int(x) for x in second.split()]
players = [nums[0], nums[1]]
nums.pop(0)
nums.pop(0)
if n == 2:
	print(max(players))
else:
	while 1:
		winner = max(players)
		if len(nums) <= k - 1 and max(nums) < winner:
			print(winner)
			break
		elif max(nums[:k - 1]) < winner:
			print(winner)
			break
		else:
			nums.append(min(players))
			players.remove(min(players))
			players.append(nums[0])
			nums.pop(0)


(n, k) = [int(i) for i in input().split()]
l = [int(i) for i in input().split(' ')]
cur = 0
winner = l[0]
if len(l) == 2:
	print(2)
else:
	while cur < min(k, 501):
		if l[0] > l[1]:
			win = l[0]
			winner = win
			lose = l[1]
			l = [l[0]] + l[2:]
			l.append(lose)
			cur += 1
		else:
			win = l[1]
			lose = l[0]
			winner = win
			l = l[1:]
			l.append(lose)
			cur = 1
	print(winner)


(n, k) = [int(x) for x in input().split()]
array = [int(x) for x in input().split()]
count = 1
count1 = 0
previous_winner = -1
while count < k and count1 < n:
	winner = max(array[0], array[1])
	loser = min(array[0], array[1])
	if winner == previous_winner:
		count += 1
	else:
		previous_winner = winner
		count = 1
	array.remove(loser)
	array.append(loser)
	count1 += 1
else:
	print(array[0])


import queue
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
Q = queue.Queue()
if K > N:
	print(max(A))
else:
	(B, W) = (A[0], 0)
	for i in range(1, N):
		Q.put(A[i])
	while True:
		top = Q.get()
		if B > top:
			Q.put(top)
			W += 1
		else:
			Q.put(B)
			(B, W) = (top, 1)
		if W >= K:
			print(B)
			break


(n, m) = map(int, input().split())
powers = list(map(int, input().split()))
max_power = powers[0]
wins = 0
if m < n:
	for power in powers[1:n]:
		if max_power > power:
			wins += 1
		else:
			max_power = power
			wins = 1
		if wins == m:
			break
if m >= n or wins < m:
	max_power = max(powers)
print(max_power)


import sys
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
if k >= n - 1:
	print(max(a))
else:
	pref_max = a[0]
	for i in range(n):
		s = a[i]
		to = i + k + 1
		if s < pref_max:
			continue
		else:
			pref_max = s
			if i:
				to -= 1
		for j in range(i + 1, to):
			if a[j % n] > s:
				break
		else:
			print(s)
			sys.exit(0)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def solve():
	(n, k) = num_input()
	arr = list_input()
	if k < n:
		i = 0
		count = 0
		while i < n:
			if count == k:
				print(arr[i])
				return
			j = (i + 1) % n
			while arr[i] > arr[j]:
				count += 1
				if count == k:
					print(arr[i])
					return
				j = (j + 1) % n
			if count != k:
				i = j
				count = 1
	else:
		print(max(arr))
t = 1
for _ in range(t):
	solve()


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
wins = []
for i in range(n):
	wins.append(0)
while True:
	if a[0] > a[1]:
		a.append(a[1])
		del a[1]
		wins.append(wins[1])
		del wins[1]
		wins[0] += 1
	else:
		a.append(a[0])
		del a[0]
		wins.append(wins[0])
		del wins[0]
		wins[0] += 1
	if wins[0] == k:
		print(a[0])
		break
	elif a[0] == max(a):
		print(a[0])
		break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n - 1:
	print(max(a))
else:
	w = a[0]
	(t, q, l) = (int(w), int(k), max(a))
	for i in range(1, n):
		w = max(w, a[i])
		if w != t:
			q = int(k) - 1
		else:
			q -= 1
		t = int(w)
		if q == 0 or w == l:
			break
	print(w)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
if k >= n - 1:
	print(max(lst))
else:
	cnt = 0
	temp = lst[0]
	while True:
		if temp > lst[1]:
			cnt += 1
			lst.append(lst[1])
			lst.pop(1)
		else:
			lst.append(temp)
			lst.pop(0)
			temp = lst[0]
			cnt = 1
		if cnt == k:
			print(temp)
			break


from collections import deque
(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
if k >= n:
	print(max(list1))
else:
	win = 0
	winer = list1[0]
	flag = True
	while win < k:
		if list1[0] < list1[1]:
			list1.append(list1[0])
			list1.pop(0)
			winer = list1[0]
			win = 1
		else:
			win += 1
			list1.append(list1[1])
			list1.pop(1)
	print(winer)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = a[::-1]
p = max(a)
score = [0] + [0] * p
from collections import *
b = deque(b)
while score[b[-1]] != k and b[-1] != p:
	x = b.pop()
	y = b.pop()
	b.appendleft(min(x, y))
	b.append(max(x, y))
	score[max(x, y)] += 1
print(b[-1])


nk = input().split()
p = input().split()
playerCount = int(nk[0])
winsRequired = int(nk[1])
winnerWins = 0
newWinner = 0
currentWinner = 0
if int(playerCount) < int(winsRequired):
	currentWinner = playerCount
	winnerWins = winsRequired
while winnerWins < winsRequired:
	newWinner = 0
	if int(p[0]) > int(p[1]):
		newWinner = int(p[0])
		p.append(int(p[1]))
		p.pop(1)
	else:
		newWinner = int(p[1])
		p.append(int(p[0]))
		p.pop(0)
	if newWinner == currentWinner:
		winnerWins += 1
	else:
		currentWinner = newWinner
		winnerWins = 1
print(str(currentWinner))


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
mx = max(a)
num = a[0]
if a[0] == mx:
	print(a[0])
	sys.exit()
count = 0
for i in range(1, n):
	if a[i] < num:
		count += 1
	elif a[i] == mx:
		print(mx)
		sys.exit()
	else:
		count = 0
		num = a[i]
		count = 1
	if count == k:
		print(num)
		sys.exit()


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
j = 0
maxx = 0
a = 1
for i in t:
	if i > maxx:
		maxx = i
		h = 1
		if a == 1:
			h = h - 1
			a = 0
	else:
		h += 1
	if h == k:
		break
print(maxx)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k > n:
	print(max(a))
	exit()
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) = map(int, input().split())
a = list(map(int, input().split()))
c = []
b = []
for j in range(n):
	c.append(0)
for s in a:
	b.append(s)
if k >= n:
	print(max(a))
else:
	wins = 0
	while wins < k:
		if a[0] > a[1]:
			c[b.index(a[0])] = c[b.index(a[0])] + 1
			a.append(a[1])
			a.remove(a[1])
		else:
			c[b.index(a[1])] = c[b.index(a[1])] + 1
			a.append(a[0])
			a.remove(a[0])
		wins = max(c)
	for alp in c:
		if alp == k:
			print(b[c.index(alp)])


from collections import deque
players = []
p1 = 0
p2 = 0
wins = 0
isP1Stronk = True
(n, k) = input().split()
players = input().split()
p1 = players[0]
players.pop(0)
p2 = players[0]
power = p1
rotations = 0
while wins < int(k):
	if rotations > int(n):
		break
	if int(p1) > int(p2):
		players.append(p2)
		players.pop(0)
		p2 = players[0]
		wins += 1
		rotations += 1
	else:
		wins = 1
		power = p2
		players.append(p1)
		p1 = p2
		players.pop(0)
		p2 = players[0]
		rotations += 1
print(power)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
i = 1
t = arr[0]
while i < n:
	if arr[0] > arr[1]:
		arr.append(arr[1])
		del arr[1]
		count += 1
	else:
		arr.append(arr[0])
		del arr[0]
		count = 1
	if count == k:
		print(arr[0])
		break
	i += 1
if count != k:
	print(n)


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))
	exit()
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))


cin = lambda : list(map(int, input().split()))
(n, k) = cin()
A = cin()
C = [0 for i in range(n + 1)]
while True:
	if A[0] > A[1]:
		(A[0], A[1]) = (A[1], A[0])
	A = A[1:] + A[:1]
	C[A[0]] += 1
	if A[0] == n or C[A[0]] >= k:
		print(A[0])
		break


(playersCount, winNumber) = [int(x) for x in input().split(' ')]
players = [int(x) for x in input().split(' ')]
winsCount = 0
max = 0
for i in range(1, playersCount):
	if players[max] > players[i]:
		winsCount += 1
	else:
		winsCount = 1
		max = i
	if winsCount >= winNumber:
		break
print(players[max])


inputParameter = input()
inputArrayContentFinal = [int(x) for x in input().split()]
counter = 0
anothercounter = 0
inputParameterFinal = inputParameter.split(' ')
arrayLength = inputParameterFinal[0]
gamesToWin = int(inputParameterFinal[1])
while counter < gamesToWin:
	if len(inputArrayContentFinal) == 1:
		print(inputArrayContentFinal[0])
		break
	if counter == gamesToWin:
		print(inputArrayContentFinal[0])
	if inputArrayContentFinal[0] > inputArrayContentFinal[1]:
		counter = counter + 1
		inputArrayContentFinal.pop(1)
		if counter == gamesToWin:
			print(inputArrayContentFinal[0])
	elif inputArrayContentFinal[0] < inputArrayContentFinal[1]:
		inputArrayContentFinal[0] = inputArrayContentFinal[1]
		inputArrayContentFinal.pop(1)
		counter = 1
		if counter == gamesToWin:
			print(inputArrayContentFinal[0])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cnt = 1
m = max(l[1], l[0])
for i in range(2, n):
	if cnt == k:
		break
	if l[i] > m:
		m = l[i]
		cnt = 1
	else:
		cnt += 1
print(m)


(n, k) = 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) = map(int, input().split())
a = list(map(lambda x: [int(x), 0], input().split()))
while True:
	if a[0][0] > a[1][0]:
		tmp = a[1]
		a[0][1] += 1
		a.remove(tmp)
		a.append(tmp)
	else:
		tmp = a[0]
		a[1][1] += 1
		a.remove(tmp)
		a.append(tmp)
	if a[0][1] == k:
		break
	if a[0][1] > 10 * n:
		break
print(a[0][0])


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
max_power = powers[0]
for a in powers:
	if max_power < a:
		max_power = a
if n == 2 or k > n - 2 or powers[0] == max_power:
	print(max_power)
else:
	temp_max = 0
	number_of_wins = 0
	for a in powers:
		if a > temp_max:
			if not temp_max:
				number_of_wins = 0
			else:
				number_of_wins = 1
			temp_max = a
		else:
			number_of_wins += 1
			if number_of_wins == k:
				print(temp_max)
				break
	if number_of_wins != k:
		print(max_power)


(n, w) = map(int, input().split())
arr = list(map(int, input().split()))
winner = arr[0]
consecutivesWins = 0
for i in range(1, n):
	if consecutivesWins == w:
		break
	elif winner < arr[i]:
		winner = arr[i]
		consecutivesWins = 1
	else:
		consecutivesWins += 1
print(winner)


from collections import deque
(n, k) = map(int, input().rstrip().split())
if n <= k:
	k = n - 1
power = deque(map(int, input().rstrip().split()))
winner = power.popleft()
winCount = 0
while winCount != k:
	enemy = power[0]
	compare = max(winner, enemy)
	if winner == compare:
		power.append(enemy)
		power.popleft()
		winCount += 1
	else:
		power.append(winner)
		winner = power.popleft()
		winCount = 1
print(winner)


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


def pingpong(n, k, a):
	ans = a[0]
	wins = 0
	for i in range(1, n):
		if wins >= k:
			return ans
		if ans > a[i]:
			wins = wins + 1
		else:
			wins = 1
			ans = a[i]
	return ans
b = list(map(int, input('').split()))
n = b[0]
k = b[1]
a = list(map(int, input('').split()))
print(pingpong(n, k, a))


s1 = input()
n = int(s1.split()[0])
k = int(s1.split()[1])
s2 = input()
pl = []
for i in s2.split():
	pl.append(int(i))
rang = True
c = 0
p1 = pl[0]
j = 1
while c != k:
	if j == n:
		break
	if p1 > pl[j]:
		j += 1
		c += 1
	else:
		p1 = pl[j]
		j += 1
		c = 1
print(p1)


(n, k) = input().split()
jogadores = input().split()
jogadores = [int(x) for x in jogadores]
if int(k) > int(n):
	vencedor = max(jogadores)
else:
	vitorias = 0
	while vitorias < int(k):
		vencedor = jogadores[0]
		if vencedor > jogadores[1]:
			jogadores.append(jogadores.pop(1))
			vitorias += 1
		else:
			jogadores.append(jogadores.pop(0))
			vitorias = 1
print(vencedor)


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
current = p[0]
j = 0
for i in range(1, n):
	if p[i] < current:
		j += 1
	else:
		current = p[i]
		j = 1
	if j == k:
		break
print(current)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = {}
maxx = l[0]
i = 1
count = 0
if n <= k:
	print(max(l))
else:
	while 1:
		if maxx > l[1]:
			ans[maxx] = ans.get(maxx, 0) + 1
			if ans[maxx] == k:
				print(maxx)
				break
			l.append(l.pop(1))
		else:
			l.append(l.pop(0))
			maxx = l[0]
			ans[maxx] = ans.get(maxx, 0) + 1
			if ans[maxx] == k:
				print(maxx)
				break
		i += 1


a = input().split()
b = input().split()
players = [int(i) for i in b]
n = int(a[0])
k = int(a[1])
winA = 0
while True:
	if players[0] > players[1]:
		winA += 1
		players.append(players.pop(1))
	elif players[1] > players[0]:
		winA = 1
		players.append(players.pop(0))
	if winA == k or max(players) == players[0]:
		print(players[0])
		break


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
wins = [0] * (len(powers) + 1)
while True:
	if powers[0] > powers[1]:
		wins[powers[0]] += 1
		t = powers[1]
		del powers[1]
		powers.append(t)
	else:
		wins[powers[1]] += 1
		t = powers[0]
		del powers[0]
		powers.append(t)
	if powers[0] == len(powers):
		print(powers[0])
		break
	if wins[powers[0]] >= k:
		print(powers[0])
		break


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
if k >= n - 1:
	print(max(p))
else:
	ma = max(p[0:k + 1])
	i = p.index(ma) + 1
	win = 1
	while True:
		if p[i % n] > ma:
			ma = p[i]
			win = 1
		else:
			win += 1
		if win == k:
			print(ma)
			break
		i += 1


nw = input().split()
playersCount = int(nw[0])
victoriesNeeded = int(nw[1])
powP = list(map(int, input().rstrip().split()))
if playersCount < victoriesNeeded:
	print(max(powP))
else:
	win = 0
	while win < victoriesNeeded:
		if int(powP[0]) > int(powP[1]):
			powP.append(powP.pop(1))
			win = win + 1
		else:
			win = 0
			powP.append(powP.pop(0))
			win = win + 1
	print(powP[0])


from collections import deque

def TableTennis(pw, power):
	wins = 0
	power = deque(power)
	p1 = power.popleft()
	p2 = power[0]
	if len(power) == 1:
		if p1 > p2:
			print(p1)
		else:
			print(p2)
	else:
		while wins != pw[1]:
			if pw[1] > 500 and wins > 500:
				break
			if p1 > p2:
				p2 = power.popleft()
				power.append(p2)
				p2 = power[0]
				wins += 1
			else:
				power.append(p1)
				p2 = power.popleft()
				p1 = p2
				p2 = power[0]
				wins = 1
		print(p1)
pw = [int(x) for x in input().split()]
power = [int(x) for x in input().split()]
TableTennis(pw, power)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = list(map(int, input().rstrip().split()))
index = k
count = 0
while index > 0:
	if a[0] > a[1]:
		a.append(a[1])
		a.pop(1)
	else:
		a.append(a[0])
		a.pop(0)
		index = k
	index -= 1
	count += 1
	if count == n - 1:
		break
print(a[0])


(n, k) = map(int, input().split())
array = list(map(int, input().split()))
winner = array[0]
count = 0
for i in range(1, len(array)):
	if array[i] > winner:
		winner = array[i]
		count = 1
	elif array[i] < winner:
		count += 1
	if count == k:
		break
print(winner)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n:
	print(max(a))
else:
	for i in range(k - 1):
		a.append(a[i])
	if max(a[0:k + 1]) == a[0]:
		print(a[0])
	else:
		i = a.index(max(a[0:k + 1]))
		while True:
			ma = max(a[i:i + k])
			if ma == a[i]:
				print(ma)
				break
			else:
				i = a.index(ma)


(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


from queue import Queue
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
q = Queue()
if k > n:
	print(max(a))
else:
	(best, wins) = (a[0], 0)
	for i in range(1, n):
		q.put(a[i])
	while True:
		top = q.get()
		if best > top:
			q.put(top)
			wins += 1
		else:
			q.put(best)
			(best, wins) = (top, 1)
		if wins >= k:
			print(best)
			break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
wins = 0
bigger = a[0]
found = False
for i in range(1, n):
	if bigger == n:
		print(n)
		found = True
		break
	if bigger > a[i]:
		wins += 1
	else:
		bigger = a[i]
		wins = 1
	if wins == k:
		print(bigger)
		found = True
		break
if not found:
	print(bigger)


first = input()
firstsplit = first.split()
n = int(firstsplit[0])
k = int(firstsplit[1])
second = input()
players = second.split()
players = [int(i) for i in players]
wins = 0
if players[0] > players[1]:
	champion = players.pop(0)
	wins = wins + 1
	y = players.pop(0)
	players.append(y)
else:
	champion = players.pop(1)
	wins = wins + 1
	y = players.pop(0)
	players.append(y)
while wins < k:
	if wins > n:
		break
	x = players.pop(0)
	if champion > x:
		players.append(x)
		wins = wins + 1
	else:
		players.append(champion)
		champion = x
		wins = 1
print(champion)


import queue
q = queue.Queue()
t1 = input()
t1 = t1.split(' ')
pNum = int(t1[0])
lNum = int(t1[1])
t2 = input()
t2 = t2.split(' ')
maxf = 0
maxn = 0
i = 0
l = len(t2)
while i < l:
	t2[i] = int(t2[i])
	q.put(t2[i])
	if maxf < t2[i]:
		maxf = t2[i]
		maxn = i
	i += 1
tadd = 0
gq = 0
p = 0
tm = 0
tm = q.get()
if lNum > pNum * 2:
	print(maxf)
else:
	while True:
		temp = q.get()
		if tm > temp:
			q.put(temp)
			tadd += 1
		else:
			if gq < tadd:
				gq = tadd
			q.put(tm)
			tm = temp
			tadd = 1
		if tadd == lNum:
			break
		if p > maxn + tadd:
			break
	print(tm)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
dic = {}
curr = arr.pop(0)
dic[curr] = 0
while curr != n:
	if arr[0] == n:
		curr = n
		break
	if curr > arr[0]:
		arr.pop(0)
		dic[curr] += 1
	else:
		curr = arr.pop(0)
		dic[curr] = 1
	if dic[curr] >= k:
		break
print(curr)


[n, k] = list(map(int, input().split(' ')))
seq = list(map(int, input().split(' ')))
if k > n:
	print(max(seq))
else:
	currentWinner = max(seq[0], seq[1])
	wins = 1
	index = 2
	while True:
		if index >= len(seq) or wins == k:
			break
		winner = max(currentWinner, seq[index])
		if winner != currentWinner:
			currentWinner = winner
			wins = 1
		else:
			wins += 1
		index += 1
	print(currentWinner)


n = input().split(' ')
people_wins = [int(x) for x in n]

class Person:

	def __init__(self, power, wins):
		self.power = power
		self.win_count = wins

	def wins(self):
		self.win_count += 1
powers = input().split(' ')
queue = [Person(int(x), 0) for x in powers][::-1]
output = ''
winner = False
table = []
table.append(queue.pop())
if people_wins[1] > 501:
	people_wins[1] = 501
while winner == False:
	table.append(queue.pop())
	strongest = table[0]
	loser = []
	for contestant in table:
		if contestant.power > strongest.power:
			lost = Person(strongest.power, strongest.win_count)
			loser.append(lost)
			strongest = contestant
		else:
			loser.append(contestant)
	table.clear()
	strongest.wins()
	table.append(strongest)
	queue.insert(0, loser.pop())
	loser.clear()
	if strongest.win_count == people_wins[1]:
		winner = True
		output += str(strongest.power)
print(output)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
d = a[0]
cnt = 0
mx = d
for i in range(1, n):
	mx = max(mx, a[i])
if k >= n:
	print(mx)
	exit()
for i in range(1, n):
	if a[i] < d:
		cnt += 1
	else:
		cnt = 1
		d = a[i]
	if cnt == k:
		break
print(d)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ka = max(l[0], l[1])
c = 1
for i in range(2, n):
	if c == m:
		break
	if l[i] > ka:
		ka = l[i]
		c = 1
	else:
		c = c + 1
print(ka)


n = [int(x) for x in input().split(' ')]
poderes = [int(x) for x in input().split(' ')]
ind = 0
cont = 0
maior = poderes[0]
if n[1] > n[0]:
	print(max(poderes))
else:
	while cont < n[1]:
		if ind == n[0]:
			ind = 0
		elif poderes[ind] == maior:
			ind += 1
		elif maior > poderes[ind]:
			cont += 1
			ind += 1
		else:
			maior = poderes[ind]
			cont = 1
			ind += 1
	print(maior)


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n - 1:
	print(max(a))
	exit()
w = [0] * n
q = deque()
for i in range(n):
	q.appendleft(i)
first = q.pop()
while True:
	second = q.pop()
	if a[first] < a[second]:
		(first, second) = (second, first)
	w[first] += 1
	if w[first] == k:
		print(a[first])
		exit()
	q.appendleft(second)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
get = 1
ans = max(a[0], a[1])
for i in range(2, n):
	if ans > a[i]:
		get += 1
	else:
		ans = a[i]
		get = 1
	if get == k:
		break
print(ans)


(n, k) = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
if k > n:
	print(max(lst))
else:
	i = 0
	c = 1
	if lst[i] > lst[i + 1]:
		f = lst[i]
		lst.append(lst[i + 1])
		del lst[i + 1]
	else:
		f = lst[i + 1]
		lst.append(lst[i])
		del lst[i]
	while True:
		if max(lst[i], lst[i + 1]) == f:
			c += 1
			if lst[i] > lst[i + 1]:
				lst.append(lst[i + 1])
				del lst[i + 1]
			else:
				lst.append(lst[i])
				del lst[i]
		else:
			c = 1
			if lst[i] > lst[i + 1]:
				f = lst[i]
				lst.append(lst[i + 1])
				del lst[i + 1]
			else:
				f = lst[i + 1]
				lst.append(lst[i])
				del lst[i]
		if c == k:
			print(f)
			break


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
m = max(a)
tmp = a[0]
for i in range(1, len(a)):
	if tmp > a[i]:
		cnt += 1
	else:
		cnt = 1
		tmp = a[i]
	if cnt == k:
		print(tmp)
		sys.exit()
	if tmp == m:
		print(m)
		sys.exit()


from collections import deque
(n, k) = map(int, input().split())
if k > 5 * n:
	k = 5 * n
a = deque(reversed(list(map(int, input().split()))))
cnt = 0
while True:
	if a[-1] < a[-2]:
		cnt = 1
		a.appendleft(a.pop())
	else:
		cnt += 1
		(x, y) = (a.pop(), a.pop())
		a.appendleft(y)
		a.append(x)
	if cnt >= k:
		break
print(a[-1])


(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)


def simulate(k, l):
	l = [[l[i], i, 0] for i in range(len(l))]
	curr = l.pop(0)
	while True:
		opp = l.pop(0)
		if curr[0] > opp[0]:
			l.append(opp)
			curr[2] += 1
		else:
			l.append(curr)
			curr = [i for i in opp]
			curr[2] += 1
		if curr[2] >= k:
			return curr[0]
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k <= n:
	print(str(simulate(k, l)))
else:
	l = [(l[i], i) for i in range(len(l))]
	l.sort()
	print(str(l[-1][0]))


userInput = input()
inputL1P1 = int(userInput.split()[0])
inputL1P2 = int(userInput.split()[1])
userInput2 = input()
inputArray = userInput2.split()
inputArray = [int(x) for x in inputArray]
winCounter = 0
for i in range(inputL1P1):
	if i == inputL1P1:
		break
	if winCounter == inputL1P2:
		break
	if inputArray[0] > inputArray[i]:
		winCounter = winCounter + 1
	elif inputArray[0] < inputArray[i]:
		winCounter = 1
		inputArray[0] = inputArray[i]
print(str(inputArray[0]))


import os
import sys
from io import BytesIO, IOBase
from collections import deque
(n, k, a) = [None] * 3

def getInput() -> None:
	global n, k, a
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]

def main() -> None:
	getInput()
	global n, k, a
	d = deque(a)
	prevWinner = a[0]
	winCount = 0
	for times in range(2 * n):
		(x, y) = (d[0], d[1])
		d.popleft()
		d.popleft()
		if x > y:
			winCount += 1
			d.append(y)
			d.appendleft(x)
			prevWinner = x
		else:
			winCount = 1
			d.append(x)
			d.appendleft(y)
			prevWinner = y
		if winCount >= k:
			print(prevWinner)
			exit(0)
	print(max(d))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


linea1 = [int(x) for x in input().split()]
lista = [int(x) for x in input().split()]
total = linea1[0]
minimo = linea1[1]
ganador = 0
contador = 1
if lista[0] > lista[1]:
	ganador = lista[0]
	lista.remove(lista[1])
else:
	c = lista[0]
	ganador = lista[1]
	lista.remove(lista[0])
while contador < minimo and len(lista) != 1:
	if lista[0] > lista[1]:
		contador += 1
		lista.remove(lista[1])
	else:
		contador = 1
		c = lista[0]
		ganador = lista[1]
		lista.remove(lista[0])
print(ganador)


(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)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
if a.index(max(a)) < k or a.index(max(a)) == 0:
	print(max(a))
else:
	while max(b) < k:
		if a[0] > a[1]:
			b[0] = b[0] + 1
			x = a[1]
			y = b[1]
			a.remove(a[1])
			b.remove(b[1])
			a.append(x)
			b.append(y)
		else:
			b[1] = b[1] + 1
			x = a[0]
			y = b[0]
			a.remove(a[0])
			b.remove(b[0])
			a.append(x)
			b.append(y)
	print(a[b.index(max(b))])


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
d = {}
mx = L[0]
for i in range(1, n):
	mx = max(mx, L[i])
	if mx in d:
		d[mx] += 1
	else:
		d[mx] = 1
	if d[mx] == k:
		print(mx)
		exit()
print(mx)


(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)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cnt = [0] * n
queue = l[:]
for i in range(n):
	(a, b) = (queue[0], queue[1])
	m = max(a, b)
	mi = min(a, b)
	cnt[l.index(m)] += 1
	queue.remove(mi)
	queue[0] == m
	queue.append(mi)
	if max(cnt) == k:
		print(l[cnt.index(max(cnt))])
		quit()
print(max(l))


I = lambda : map(int, input().split())
(n, k) = I()
l = list(I())
if n <= k:
	print(max(l[:k + 1]))
else:
	victories = 1
	if l[0] > l[1]:
		v = 0
	else:
		v = 1
	for i in range(2, len(l)):
		if l[i] > l[v]:
			v = i
			victories = 1
		else:
			victories += 1
		if victories == k:
			break
	print(l[v])


p = input().rstrip().split(' ')
q = input().rstrip().split(' ')
if int(p[1]) >= len(q):
	q.sort(key=int, reverse=True)
	print(int(q[0]))
else:
	i = 0
	K = 0
	D = 0
	while 1:
		if K < int(p[1]) and D < int(p[1]):
			if int(q[i]) > int(q[i + 1]):
				if D == 0:
					K += 1
					q.append(int(q[i + 1]))
					del q[i + 1]
				else:
					K = 0
					D += 1
					q.append(int(q[i + 1]))
					del q[i + 1]
			elif D != 0:
				D = 0
				K += 1
				q.append(q[i])
				del q[i]
			else:
				K = 0
				q.append(int(q[i]))
				del q[i]
				D += 1
		else:
			break
	print(q[0])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = a[0]
c = 0
i = 1
while i < len(a):
	if t > a[i]:
		a.append(a[i])
		c += 1
	else:
		c = 1
		a.append(t)
		t = a[i]
	if c >= k:
		print(t)
		break
	if i > 2 * (n - 1):
		print(max(a))
		break
	i += 1


line = input().split(' ')
n = int(line[0])
k = int(line[1])
line = input().split(' ')
powers = [int(line[i]) for i in range(n)]
winner = 0
count = 0
if k > n - 2:
	winner = max(powers)
else:
	while True:
		if powers[0] > powers[1]:
			count += 1
			winner = powers[0]
			powers.append(powers[1])
			del powers[1]
		else:
			count = 1
			winner = powers[1]
			powers.append(powers[0])
			del powers[0]
		if count == k:
			break
print(winner)


from collections import deque, defaultdict
power_map = defaultdict(lambda : 0)
(n, k) = map(int, input().split(' '))
ai = list(map(int, input().split(' ')))
if k > n:
	print(max(ai))
else:
	a = deque(ai)
	win = 0
	while True:
		win = max(a[0], a[1])
		loose = min(a[0], a[1])
		a.remove(loose)
		a.append(loose)
		power_map[win] += 1
		if max(power_map.values()) == k:
			break
	print(win)


(n, k) = list(map(int, input().split()))
if k > n:
	print(n)
else:
	(cwinner, wins) = (0, 0)
	a = list(map(int, input().split()))
	while wins < k:
		if a[0] > a[1]:
			a[1:] = a[2:] + [a[1]]
			if cwinner == a[0]:
				wins += 1
			else:
				cwinner = a[0]
				wins = 1
		else:
			(a[0], a[1]) = (a[1], a[0])
			a[1:] = a[2:] + [a[1]]
			if cwinner == a[0]:
				wins += 1
			else:
				cwinner = a[0]
				wins = 1
	print(cwinner)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
wi1 = 0
wi2 = 0
if k > n:
	print(max(l))
else:
	w = 0
	while wi1 < k and wi2 < k:
		if l[0] > l[1]:
			wi1 += 1
			t = l[1]
			l.remove(l[1])
			l.append(t)
			wi2 = 0
		else:
			wi2 += 1
			t = l[0]
			l.remove(l[0])
			l.append(t)
			wi1 = wi2
			wi2 = 0
	print(l[0]) if wi1 == k else print(l[1])


(n, k) = map(int, input().split())
lst = [*map(int, input().split())]
(mx, cout) = (lst[0], 0)
for i in range(1, n):
	if max(mx, lst[i]) == mx:
		cout += 1
	else:
		mx = lst[i]
		cout = 1
	if cout == k:
		break
print(mx)


def tableTennis(wins, players):
	p = players
	idx = 0
	while idx < len(p):
		win_count = 0
		has_fought = []
		fight_count = 0
		while True:
			fight_count += 1
			if p[0] > p[1]:
				if fight_count == 1 and p[0] > p[-1]:
					win_count += 2
				else:
					win_count += 1
				has_fought.append(p[1])
				if win_count == wins or (len(has_fought) + 1 == len(p) and max(p) == p[0]):
					print(p[0])
					return
				else:
					temp = p[1]
					p.remove(temp)
					p.append(temp)
			else:
				val = p.pop(0)
				p.append(val)
				break
		idx += 1

def main():
	first_line = [int(x) for x in input().split(' ')]
	second_line = [int(x) for x in input().split(' ')]
	tableTennis(first_line[1], second_line)
main()


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
if n <= k:
	k = n - 1
winner = 0
count = 0
for i in range(1, n):
	if count == k:
		break
	new = max(powers[i], powers[winner])
	if powers[winner] == new:
		count += 1
	else:
		count = 1
		winner = i
print(powers[winner])


(n, k) = map(int, input().split())
A = [int(s) for s in input().split()]
MAX = max(A)
count = 0
player = 0
for i in range(n):
	if A[i] == MAX:
		print(MAX)
		break
	elif A[i] > player:
		if i > 0:
			count = 1
		player = A[i]
	else:
		count += 1
	if count == k:
		print(player)
		break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
z = 0
c = 0
b = 0
x = 0
t = a[0]
m = 0
while b + k < n:
	if b == 0:
		b == 1
	if m == 1:
		u = k
	else:
		u = k + 1
	for i in range(b, b + u):
		z = 0
		if t < a[i]:
			t = a[i]
			b = i
			z = 1
			m = 1
			break
	if z == 0:
		x = 1
		print(t)
		break
for i in range(b, n):
	t = max(t, a[i])
if x == 0:
	print(t)


import sys

def f(n, k, fo):
	c = 0
	p = 0
	w = 0
	if k >= n - 1:
		p = max(fo)
	else:
		while c < k:
			if fo[1] > fo[0]:
				c = 1
				p = fo[1]
				w = 0
			else:
				c += 1
				p = fo[0]
				w = 1
			fo.append(fo.pop(w))
	print(p)
(n, k) = list(map(int, sys.stdin.readline().split()))
fo = list(map(int, sys.stdin.readline().split()))
f(n, k, fo)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k > n:
	print(n)
else:
	curr = 0
	currpow = a[0]
	if currpow == n:
		print(n)
		sys.exit()
	for i in range(1, n):
		if a[i] > currpow:
			curr = 1
			currpow = a[i]
			if currpow == n:
				print(n)
				sys.exit()
		else:
			curr += 1
			if curr >= k:
				print(currpow)
				sys.exit()


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
tested = p[0]
wins = 0
for i in range(1, n):
	if p[i] < tested:
		wins += 1
	else:
		wins = 1
		tested = p[i]
	if wins == k:
		break
print(tested)


from collections import deque
from functools import reduce
(n, k) = [int(a) for a in input().strip().split()]
powers = deque()
for a in input().strip().split():
	powers.append(int(a))
num_wins = {x: 0 for x in powers}
if n == 1:
	print(powers[0])
elif k > n:
	print(max(powers))
else:
	current = None
	curr_max_wins = -float('inf')
	while curr_max_wins < k:
		if current is None:
			current = powers.popleft()
		else:
			challenger = powers.popleft()
			if challenger > current:
				powers.append(current)
				num_wins[challenger] += 1
				current = challenger
			else:
				powers.append(challenger)
				num_wins[current] += 1
			for (i, j) in num_wins.items():
				if j > curr_max_wins:
					curr_max_wins = j
	print(current)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k >= n - 1:
	print(max(l))
else:
	count = 0
	max = l[0]
	for i in range(1, n + k + 1):
		if max > l[i]:
			l.append(l[i])
			count += 1
		else:
			l.append(max)
			max = l[i]
			count = 1
		if count == k:
			break
	print(max)


line1 = [int(i) for i in input().split()]
n = line1[0]
k = line1[1]
players = input().split()
mapa = {}
maior = 0
result = 0
while maior < k:
	greater = players[0]
	minor = players[1]
	if int(players[1]) > int(greater):
		greater = players[1]
		minor = players[0]
	if len(players) == 2:
		result = greater
		break
	if k > 2 * len(players):
		result = max([int(j) for j in players])
		break
	if mapa.get(greater) == None:
		mapa[greater] = 1
	else:
		mapa[greater] += 1
	if mapa[greater] > maior:
		maior = mapa[greater]
		result = greater
	players.remove(minor)
	players.append(minor)
print(result)


import queue
from collections import deque

def readTuple():
	return input().split()

def readInts():
	return tuple(map(int, readTuple()))

def solve():
	(n, k) = readInts()
	if k >= 2000:
		print(n)
		return
	wins = 0
	powers = deque(readInts())
	while True:
		a = powers.popleft()
		b = powers.popleft()
		if wins >= k:
			print(a)
			break
		if a > b:
			wins += 1
		else:
			wins = 1
			(a, b) = (b, a)
		powers.appendleft(a)
		powers.append(b)
solve()


(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)


num_wins = int(input().split(' ')[1])
num_players = input().split(' ')
sub = int(num_players[0])
num_players.pop(0)
wins = 0
check = int(num_players[0])
while wins < num_wins:
	main = int(num_players[0])
	if sub > main:
		wins += 1
		if wins == num_wins:
			print(sub)
			break
		num_players.pop(0)
		num_players.append(main)
		if num_players[0] == check:
			print(sub)
			break
	else:
		wins = 1
		loser = sub
		sub = main
		check = loser
		num_players.pop(0)
		num_players.append(loser)


(n, k) = map(int, input().split())
power = list(map(int, input().split()))
if k >= n - 1:
	maxx = max(power)
	print(maxx)
else:
	myMap = {}
	done = 0
	for i in range(n):
		myMap[power[i]] = 0
	while True:
		if power[0] > power[1]:
			myMap[power[0]] += 1
			temp = power.pop(1)
			power.append(temp)
		else:
			myMap[power[1]] += 1
			temp = power.pop(0)
			power.append(temp)
		for i in range(n):
			if myMap[power[i]] >= k:
				print(power[i])
				done = 1
				break
		if done == 1:
			break


gi = lambda : list(map(int, input().split()))
(n, k) = gi()
powers = gi()
if k >= n:
	print(max(powers))
	exit()
wins = 0
while 1:
	if powers[0] > powers[1]:
		wins += 1
		loser = powers.pop(1)
		powers.append(loser)
	else:
		wins = 1
		loser = powers.pop(0)
		powers.append(loser)
	if wins == k:
		print(powers[0])
		exit()


def main():
	(n, k) = map(int, input().split())
	x = [int(x) for x in input().split()]
	if k >= n:
		print(max(x))
		return
	else:
		for i in range(0, n):
			if i + k < n:
				if i == 0:
					temp = max(x[i:i + k + 1])
				else:
					temp = max(x[i:i + k])
				if temp == x[i]:
					print(temp)
					break
				else:
					continue
			else:
				temp1 = max(x[i:n])
				tempx = k - (n - i) + 1
				temp2 = max(x[0:tempx])
				temp = max(temp1, temp2)
				if temp == x[i]:
					print(temp)
					break
				else:
					continue
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n:
	print(max(a))
else:
	a = a + a
	q = 0
	pre = a[0]
	ind = 0
	for i in range(1, n * 2):
		if pre > a[i]:
			q += 1
			if q >= k:
				print(pre)
				exit()
		else:
			q = 1
			pre = a[i]


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
if n == 2:
	print(max(a))
	exit()
if k > n:
	print(max(a))
	exit()
k += 1
a.insert(0, 10 ** 9)
for i in range(1, n - k + 2):
	if a[i] == max(a[i - 1:i + k - 1]) or a[i] == max(a[i:i + k]):
		print(a[i])
		exit()
print(max(a[1:]))


import math
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ll = list(l + l)
cnt = int(0)
if k >= n - 1:
	print(n)
else:
	for i in ll:
		if cnt == 0:
			if i == max(ll[cnt:cnt + k + 1]):
				print(i)
				break
		elif i == max(ll[cnt - 1:cnt + k]):
			print(i)
			break
		cnt += 1


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-09

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)


def solve(players, round, queue):
	index = 1
	currentStrongest = queue[0]
	winStreak = 0
	while index < players and winStreak < round:
		if currentStrongest < queue[index]:
			currentStrongest = queue[index]
			winStreak = 1
		else:
			winStreak += 1
		index += 1
	return currentStrongest
(b, g) = list(map(int, input().split()))
seq = list(map(int, input().split()))
print(solve(b, g, seq))


import math
import os
import random
import re
import sys
playerWins = input().split()
player = int(playerWins[0])
wins = int(playerWins[1])
powerValue = list(map(int, input().rstrip().split()[:player]))
a = 0
checker = []
if wins > 1000:
	wins = 1000
while len(checker) < wins:
	if powerValue[a] > powerValue[a + 1]:
		checker.append(powerValue[a + 1])
		powerValue.append(powerValue[a + 1])
		del powerValue[a + 1]
	elif powerValue[a] < powerValue[a + 1]:
		powerValue.append(powerValue[a])
		del powerValue[a]
		checker.clear()
		checker.append(powerValue[a + 1])
print(powerValue[a])


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
p = z[0]
s = 0
for i in range(1, a):
	if z[i] < p:
		s += 1
	else:
		s = 1
		p = z[i]
	if s >= b:
		break
print(p)


from collections import Counter
(n, k) = map(int, input().split())
a = map(int, input().split())
d = Counter()
p1 = next(a)
for p2 in a:
	if p1 > p2:
		d[p1] += 1
	else:
		d[p2] += 1
		p1 = p2
	if d[p1] >= k:
		print(p1)
		exit(0)
print(n)


(n, k) = map(int, input().split(' '))
numbers = list(map(int, input().split(' ')))
best = max(numbers)

def f():
	if k >= n:
		print(best)
		return
	else:
		current_best = numbers[0]
		if numbers[0] == best:
			print(best)
			return
		winners = 0
		for i in numbers[1:]:
			if i == best:
				print(best)
				return
			elif i > current_best:
				current_best = i
				winners = 1
			else:
				winners += 1
			if winners >= k:
				print(current_best)
				return
f()


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
a = t[0]
p = 0
h = -1
for j in range(n):
	if a > t[j]:
		p += 1
	elif a < t[j]:
		a = t[j]
		p = 1
	if p == k:
		h = a
		break
if h != -1:
	print(h)
else:
	print(max(t))


bruhMoment = input().split()
n = int(bruhMoment[0])
k = int(bruhMoment[-1])
bruhMomentX = input().split()
winCounter = 0
for i in range(1, n):
	if int(bruhMomentX[0]) > int(bruhMomentX[i]):
		winCounter += 1
	else:
		(bruhMomentX[0], bruhMomentX[i]) = (bruhMomentX[i], bruhMomentX[0])
		winCounter = 1
	if winCounter == k:
		break
print(bruhMomentX[0])


from collections import deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = deque(a)
b = [0] * (n + 1)
dk = max(a)
while max(b) < k:
	if a[0] == dk:
		print(dk)
		exit()
	if a[0] > a[1]:
		b[a[0]] += 1
		aa = a.popleft()
		bb = a.popleft()
		a.appendleft(aa)
		a.append(bb)
	else:
		b[a[1]] += 1
		aa = a.popleft()
		bb = a.popleft()
		a.append(aa)
		a.appendleft(bb)
d = max(b)
for i in range(n + 1):
	if b[i] == d:
		print(i)


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


from sys import *
from math import *
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
if k >= n:
	print(max(a))
else:
	j = 0
	while j < k:
		if a[0] > a[1]:
			a.append(a.pop(1))
			j += 1
		else:
			a.append(a.pop(0))
			j = 1
	print(a[0])


from math import ceil
(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))

def sim():
	global p
	(a, p) = (p[0], p[1:])
	c = 0
	while 1:
		(b, p) = (p[0], p[1:])
		while a > b:
			c += 1
			if c >= k:
				return a
			p.append(b)
			(b, p) = (p[0], p[1:])
		c = 1
		p.append(a)
		a = b
if k >= n - 1:
	print(max(p))
else:
	print(sim())


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
C = [0] * n
t = 0
p = 1
if k <= n:
	while True:
		if A[t] > A[p]:
			A.append(A[p])
			if C[A[t] - 1] == k - 1:
				print(A[t])
				break
			else:
				C[A[t] - 1] += 1
		else:
			A.append(A[t])
			t = p
			if C[A[p] - 1] == k - 1:
				print(A[p])
				break
			else:
				C[A[p] - 1] += 1
		p += 1
else:
	A.sort()
	print(A[-1])


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
a = max(m)
d = max(m[0], m[1])
s = 1
for i in m[2:]:
	if i == a:
		d = a
		break
	if i > d:
		d = i
		s = 1
	else:
		s += 1
	if s == k:
		break
print(d)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if k >= n:
	print(max(arr))
else:
	len = len(arr)
	cnt = 0
	prev_ans = -1
	ans = 0
	for idx in range(2000):
		idx = idx + 1
		mini = min(arr[idx], arr[idx - 1])
		maxi = max(arr[idx], arr[idx - 1])
		if arr[idx - 1] > arr[idx]:
			(arr[idx], arr[idx - 1]) = (arr[idx - 1], arr[idx])
		ans = maxi
		if prev_ans != ans:
			cnt = 0
			prev_ans = ans
		arr.append(mini)
		cnt += 1
		if cnt >= k:
			print(ans)
			break


from copy import copy
from collections import deque
in_1 = input().split()
n = int(in_1[0])
k = int(in_1[1])
in_2 = input().split()
current_player = int(in_2[0])
current_opponent = int(in_2[1])
enemy_q = deque()
current_wins = 0
if n > 2:
	for i in in_2[2:]:
		enemy_q.appendleft(int(i))
	while current_wins < k:
		if current_player > current_opponent:
			enemy_q.appendleft(current_opponent)
			current_wins += 1
			current_opponent = enemy_q.pop()
			if current_wins > n - 1:
				break
		else:
			winner = copy(current_opponent)
			enemy_q.appendleft(current_player)
			current_player = winner
			current_wins = 1
			current_opponent = enemy_q.pop()
elif current_player < current_opponent:
	current_player = current_opponent
print(current_player)


(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) = map(int, input().split())
po = [int(x) for x in input().split()]
if n <= k:
	print(max(po))
	exit(0)
w = -1
l = -1
i = 0
j = i + 1
total = 0
chn = True
while total < k:
	if po[i] > po[j]:
		w = i
		l = j
		total += 1
		po.append(po.pop(l))
		chn = True
	else:
		if chn:
			total = 0
		w = j
		l = i
		po.append(po.pop(l))
		total += 1
print(po[i])


(n, k) = map(int, input().rstrip().split(' '))
players = list(map(int, input().rstrip().split(' ')))
if n <= k:
	k = n - 1
playerWinner = 0
countUntilWin = 0
for i in range(1, n):
	tempComp = max(players[i], players[playerWinner])
	if players[playerWinner] == tempComp:
		countUntilWin += 1
	else:
		countUntilWin = 1
		playerWinner = i
	if countUntilWin == k:
		break
print(players[playerWinner])


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)


a = list(map(int, input().rstrip().split()))
player = list(map(int, input().rstrip().split()))
win = 0
x = player.pop(0)

def findWinner(x, player, win):
	if a[0] == 2:
		if x > player[0]:
			return x
		else:
			return player[0]
	elif a[0] >= 20 and player == sorted(player):
		return player[len(player) - 1]
	elif a[0] >= 20 and player == sorted(player, reverse=True):
		if x > player[0]:
			return x
		else:
			return player[0]
	elif x > player[0]:
		win += 1
		if win == a[1] or win == a[0] + 1:
			return x
		else:
			player.append(player.pop(0))
			return findWinner(x, player, win)
	else:
		win = 1
		player.append(x)
		x = player.pop(0)
		return findWinner(x, player, win)
print(findWinner(x, player, win))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
(t, i, j) = (0, 0, 1)
test = 1
if n < k:
	print(max(l))
	test = 0
while t < k and test:
	if l[i] > l[j]:
		t += 1
		j += 1
	else:
		i = j
		j += 1
		t = 1
	if j == n:
		j = 0
if test:
	print(l[i])


(n, k) = map(int, input().split())
a = [int(f) for f in input().split()]
(b, pob) = (0, a[0])
for i in range(1, n):
	if pob > a[i]:
		b += 1
	if pob < a[i]:
		pob = a[i]
		b = 1
	if b == k:
		break
print(pob)


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
win = 0
champ = powers[0]
i = 1
while i < len(powers):
	if win == k:
		break
	prox = powers[i]
	if champ > prox:
		win += 1
	else:
		champ = prox
		win = 1
	i += 1
print(champ)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
sequence = list(map(int, input().split()))
wins = k
winner = sequence[0]
if k >= n:
	print(max(sequence))
else:
	while wins > 0:
		if winner > sequence[1]:
			wins -= 1
			sequence.append(sequence[1])
			sequence.pop(1)
		else:
			wins = k - 1
			sequence.append(sequence[0])
			sequence.pop(0)
			winner = sequence[0]
	print(winner)


(num_de_pessoas, num_de_vitorias) = map(int, input().split())
habilidades = list(map(int, input().split()))
aux = 0
if num_de_pessoas <= 2:
	print(max(habilidades))
else:
	while aux < num_de_vitorias:
		if habilidades[0] > habilidades[1]:
			jogador = habilidades[1]
			habilidades.remove(jogador)
			habilidades.append(jogador)
			aux += 1
			if habilidades[0] == num_de_pessoas:
				aux = num_de_vitorias
		else:
			jogador = habilidades[0]
			habilidades.remove(jogador)
			habilidades.append(jogador)
			aux = 1
	print(habilidades[0])


(n, k) = map(int, input().split())
po = list(map(int, input().split()))
if k >= len(po):
	print(max(po))
else:
	wins = 0
	q = po[:]
	while wins != k:
		cp = q.pop(0)
		while True:
			i = q[0]
			if i < cp:
				wins += 1
				q.append(q.pop(0))
			else:
				wins = 1
				q.append(cp)
				break
			if wins == k:
				break
	print(cp)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
s = 0
pre = l[0]
for i in range(1, a):
	if pre > l[i]:
		s += 1
	else:
		pre = l[i]
		s = 1
	if s == b:
		break
print(pre)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
if k >= n - 1:
	print(max(s))
else:
	dic = {}
	m = s[0]
	while 1:
		(a, b) = (max(s[0], s[1]), min(s[0], s[1]))
		s[1] = a
		s.append(b)
		s = s[1:]
		dic[a] = dic.get(a, 0) + 1
		if dic[a] == k:
			print(a)
			break


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if n <= k:
	l.sort()
	l.reverse()
	print(l[0])
else:
	t = 0
	while t < k:
		if l[0] > l[1]:
			x = l[1]
			l.remove(l[1])
			l.append(x)
			t += 1
		elif l[1] > l[0]:
			x = l[0]
			l.remove(l[0])
			l.append(x)
			t = 1
	print(l[0])


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
quee = deque()
(n, k) = zzz()
quee.extend(zzz())
cnt = 0
maxper = max(list(quee))
last_per = -1
while True:
	u = quee.popleft()
	v = quee.popleft()
	loser = min(u, v)
	win = max(u, v)
	if win == last_per:
		cnt += 1
	else:
		cnt = 1
		last_per = win
	if cnt == k:
		break
	if win == maxper:
		break
	quee.append(loser)
	quee.appendleft(win)
print(last_per)


(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)


(n, k) = list(map(int, input().split()))
number = list(map(int, input().split()))
if k >= n:
	print(max(number))
else:
	flag = 0
	i = 0
	while i < n - k + 1:
		if i == 0 and max(number[i:i + k + 1]) == number[i]:
			flag = 1
			print(number[i])
			break
		elif i != 0 and max(number[i - 1:i + k]) == number[i]:
			flag = 1
			print(number[i])
			break
		else:
			i += 1
	if flag == 0:
		print(max(number))


def main():
	(n, k) = map(int, input().split())
	(m, *bb) = map(int, input().split())
	if k < n:
		c = 0
		for i in range(3):
			(aa, bb) = (bb, [])
			for a in aa:
				if m < a:
					bb.append(m)
					(m, c) = (a, 1)
				else:
					bb.append(a)
					c += 1
					if c == k:
						print(m)
						return
	print(n)
main()


from collections import *
Q = deque()
(n, k) = [int(x) for x in input().split()]
Q.extend([int(x) for x in input().split()])
cnt = 0
maximo = max(list(Q))
last_winner = -1
while True:
	u = Q.popleft()
	v = Q.popleft()
	loser = min(u, v)
	winner = max(u, v)
	if winner == last_winner:
		cnt += 1
	else:
		cnt = 1
		last_winner = winner
	if cnt == k:
		break
	if winner == maximo:
		break
	Q.append(loser)
	Q.appendleft(winner)
print(last_winner)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
players = [int(i) for i in input().split()]
if k > n:
	print(max(players))
else:
	playing = players[0:2]
	queue = players[2:]
	win = False
	wins = 0
	while wins < k:
		if playing[0] > playing[1]:
			wins += 1
			queue.append(playing[1])
			playing[1] = queue.pop(0)
		else:
			wins = 1
			(playing[0], playing[1]) = (playing[1], playing[0])
			queue.append(playing[1])
			playing[1] = queue.pop(0)
	print(playing[0])


def pingpong():
	(n, k) = map(int, input().split())
	powers = list(map(int, input().split()))
	champ = powers[0]
	winCount = 0
	for i in range(1, n):
		if powers[i] < champ:
			winCount += 1
		else:
			champ = powers[i]
			winCount = 1
		if winCount == k:
			break
	print(champ)
pingpong()


from collections import deque

def ping_pong(wins, numPlayers):
	pongers = deque(numPlayers)
	iterateCounter = 0
	while iterateCounter < len(pongers):
		winsCounter = 0
		fightsCounter = 0
		pongerFought = []
		while True:
			fightsCounter += 1
			if pongers[0] > pongers[1]:
				if pongers[0] > pongers[-1] and fightsCounter == 1:
					winsCounter += 2
				else:
					winsCounter += 1
				pongerFought.append(pongers[1])
				if winsCounter == wins or (len(pongerFought) + 1 == len(pongers) and max(pongers) == pongers[0]):
					print(pongers[0])
					return
				else:
					temp = pongers[1]
					pongers.remove(temp)
					pongers.append(temp)
			else:
				val = pongers.popleft()
				pongers.append(val)
				break
		iterateCounter += 1
first_line = [int(a) for a in input().split(' ')]
second_line = [int(a) for a in input().split(' ')]
ping_pong(first_line[1], second_line)


getInput = input().split()
numWins = int(getInput[1])
numPlayers = int(getInput[0])
playerPower = input().split()
Power = []
for i in playerPower:
	Power.append(int(i))
countWin = 0
if len(Power) <= 3:
	print(max(Power))
elif Power.index(max(Power)) < numWins:
	print(max(Power))
else:
	while countWin != numWins:
		if Power[0] > Power[1]:
			Power.append(Power.pop(1))
			countWin += 1
		else:
			Power.append(Power.pop(0))
			if countWin > 0:
				countWin = 1
			else:
				countWin = 1
	print(Power[0])


min_wins = int(input().split(' ')[1])
players = input().split(' ')
sitter = int(players[0])
players.pop(0)
wins = 0
repeat_check = int(players[0])
while wins < min_wins:
	head = int(players[0])
	if sitter > head:
		wins += 1
		if wins == min_wins:
			print(sitter)
			quit()
		players.pop(0)
		players.append(head)
		if players[0] == repeat_check:
			print(sitter)
			quit()
	else:
		wins = 1
		loser = sitter
		sitter = head
		repeat_check = loser
		players.pop(0)
		players.append(loser)


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
flag = 0
cnt = k
while flag != n and cnt != 0:
	if x[0] > x[1]:
		x.append(x[1])
		del x[1]
		cnt -= 1
		flag += 1
	elif x[0] < x[1]:
		x.append(x[0])
		del x[0]
		cnt = k - 1
		flag = 0
print(x[0])


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
l = 0
k1 = 0
p = 0
while k1 != k and p != n:
	g1 = A[l]
	l += 1
	g2 = A[l]
	w = max(g1, g2)
	A[l] = w
	A.append(min(g1, g2))
	if w == p:
		k1 += 1
	else:
		p = w
		k1 = 1
print(p)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
maxi = -1
index = -1
for i in range(n):
	if a[i] > maxi:
		maxi = a[i]
		index = i
import sys
if k >= index:
	print(maxi)
else:
	count = 0
	while a[0] != maxi:
		if a[0] > a[1]:
			count += 1
			if count == k:
				print(a[0])
				sys.exit()
			a = [a[0]] + a[2:] + [a[1]]
		else:
			count = 1
			a = [a[1]] + a[2:] + [a[0]]
	if a[0] == maxi:
		print(maxi)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = max(l)
count = 0
p = l[0]
i = 1
flag = 0
if n == 2:
	if p > l[1]:
		print(p)
	else:
		print(l[1])
else:
	while count != k:
		if i == n:
			p = m
			flag = 1
			break
		if p > l[i]:
			count = count + 1
			l.append(l[i])
		else:
			count = 1
			l.append(p)
			p = l[i]
		i = i + 1
	print(p)


(numofplayers, neededwins) = [int(x) for x in input().split()]
line = [int(x) for x in input().split()]
players = list(line)
champ = line.pop(0)
wins = 0
for x in range(numofplayers - 1):
	newbie = line.pop(0)
	if champ > newbie:
		wins = wins + 1
	else:
		champ = newbie
		wins = 1
	if wins == neededwins:
		break
if line:
	print(champ)
else:
	print(max(players))


def tabletennis(pl, w):
	i = 0
	p1 = pl[0]
	p2 = pl[1]
	if p1 > p2:
		r = pl.pop(1)
		pl.append(r)
	else:
		p1 = p2
		r = pl.pop(0)
		pl.append(r)
	i += 1
	while i != w:
		if p1 > pl[1]:
			i += 1
			pl.append(pl[1])
			pl.pop(1)
		else:
			i = 1
			pl.append(pl[0])
			pl.pop(0)
			p1 = pl[0]
		if i > len(pl):
			break
	return p1
pw = input().split()
p = int(pw[0])
w = int(pw[1])
pl = list(map(int, input().rstrip().split()))
print(tabletennis(pl, w))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(d, t) = (a[0], 0)
for i in range(1, n):
	if a[i] < d:
		t += 1
	else:
		d = a[i]
		t = 1
	if t == k:
		break
print(d)


from collections import deque

def funcao(queue, k):
	if k >= len(queue):
		return max(queue)
	win = queue.popleft()
	cont = 0
	while cont < k:
		prox = queue.popleft()
		if win >= prox:
			queue.append(prox)
			cont += 1
		else:
			queue.append(win)
			win = prox
			cont = 1
	return win
k = int(input().split()[1])
lista = map(int, input().split())
queue = deque(lista)
print(funcao(queue, k))


(n, k) = input().split()
(n, k) = (int(n), int(k))
a = [int(i) for i in input().strip().split()]
if k >= n:
	print(max(a))
else:
	tmp = a[0]
	count = 0
	for i in range(1, n):
		if tmp > a[i]:
			count = count + 1
			if count == k:
				break
		else:
			count = 1
			tmp = a[i]
	print(tmp)


class Solver:

	def run(self):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		if k < n:
			w = 0
			j = 0
			for i in range(1, n):
				if a[i] > a[j]:
					w = 1
					j = i
				else:
					w += 1
				if w == k:
					print(a[j])
					return
		print(max(a))
Solver().run()


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
current_plyr_pwr = powers[0]
current_plyr_wn = 0
for i in range(1, n):
	if powers[i] < current_plyr_pwr:
		current_plyr_wn += 1
	else:
		current_plyr_pwr = powers[i]
		current_plyr_wn = 1
	if current_plyr_wn == k:
		break
print(current_plyr_pwr)


(n, k) = map(int, input().split())
p = list(map(int, input().split()))
current_player_power = p[0]
current_player_wins = 0
for i in range(1, n):
	if p[i] < current_player_power:
		current_player_wins += 1
	else:
		current_player_power = p[i]
		current_player_wins = 1
	if current_player_wins == k:
		break
print(current_player_power)


(n, k) = map(int, input().split())
powers = list(map(int, input().split()))
curr_player_power = powers[0]
curr_player_wins = 0
for i in range(1, n):
	if powers[i] < curr_player_power:
		curr_player_wins += 1
	else:
		curr_player_power = powers[i]
		curr_player_wins = 1
	if curr_player_wins == k:
		break
print(curr_player_power)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
streak = 0
while streak < k:
	if a[0] > a[1]:
		val = a[1]
		a.remove(val)
		a.append(val)
		streak += 1
		if a[0] == n:
			streak = k
	else:
		val = a[0]
		a.remove(val)
		a.append(val)
		streak = 1
print(a[0])


conditions = input()
(nums, wins) = conditions.split()
n = int(nums)
k = int(wins)
powers = input()
powersList = powers.split(' ')
powerValues = [int(x) for x in powersList]
i = 0
winCounter = []
if k > 1000:
	k = 1000
while len(winCounter) < k:
	if powerValues[i] > powerValues[i + 1]:
		winCounter.append(powerValues[i + 1])
		powerValues.append(powerValues[i + 1])
		del powerValues[i + 1]
	elif powerValues[i] < powerValues[i + 1]:
		powerValues.append(powerValues[i])
		del powerValues[i]
		winCounter.clear()
		winCounter.append(powerValues[i + 1])
print(powerValues[i])


(pp_num, wins_time) = list(map(int, input().split()))
pp = list(map(int, input().split()))
cnt = 0
while cnt != wins_time:
	if pp[0] == max(pp):
		break
	if pp[0] > pp[1]:
		pp = [pp[0]] + pp[2:] + [pp[1]]
		cnt += 1
	else:
		pp = pp[1:] + pp[0:1]
		cnt = 1
print(pp[0])


(n, k) = map(int, input().split())
a = [None] * n
a = list(map(int, input().split()))
c = 0
while c != k:
	x = 0
	for i in range(1, n):
		if a[0] > a[i]:
			x += 1
		else:
			break
	if x == k or x == n - 1:
		c = k
		break
	elif a[0] > a[1]:
		t = a[1]
		a.pop(1)
		a.append(t)
		c += 1
	elif a[0] < a[1]:
		t = a[0]
		a.pop(0)
		a.append(t)
		c = 1
print(a[0])


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


(n, l) = map(int, input().split())
v = list(map(int, input().split()))
occ = 0
max = v[0]
for i in range(1, n):
	if max > v[i]:
		occ += 1
	else:
		max = v[i]
		occ = 1
	if occ == l:
		break
print(max)


IL = lambda : list(map(int, input().split()))
I = lambda : int(input())
(n, k) = IL()
a = IL()
ans = 0
score = 0
for i in range(n - 1):
	if a[0] > a[1]:
		score += 1
	else:
		score = 1
	if score == k:
		ans = a[0]
		break
	(p1, p2) = a[:2]
	a.pop(0)
	a[0] = max(p1, p2)
	a.append(min(p1, p2))
if ans == 0:
	ans = max(a)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n:
	print(max(a))
else:
	(res, z) = (0, 0)
	for i in range(n + k):
		if a[res % n] > a[(i + 1) % n]:
			z += 1
		else:
			(res, z) = (i + 1, 1)
		if z == k:
			print(a[res])
			break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k > n:
	print(n)
else:
	cur = a[0]
	hod = -1
	ans = n
	for x in a:
		if x > cur:
			if hod >= k:
				ans = min(ans, cur)
			cur = x
			hod = 1
		else:
			hod += 1
	print(ans)


from collections import deque
(playerCount, playerWins) = [int(i) for i in input().strip().split()]
playerPower = [int(i) for i in input().strip().split()]
pP = deque()
breakLoop = False
for i in range(playerCount):
	pP.append(playerPower[i])
pPdict = {i: 0 for i in pP}
if playerCount == 1:
	print(pP[0])
elif playerWins >= playerCount:
	print(max(playerPower))
else:
	winner = pP.popleft()
	while True:
		challenger = pP.popleft()
		if winner > challenger:
			pP.append(challenger)
			pPdict[winner] += 1
		else:
			pP.append(winner)
			winner = challenger
			pPdict[challenger] += 1
		for (key, value) in pPdict.items():
			if value >= playerWins:
				print(key)
				breakLoop = True
		if breakLoop:
			break


(n, k) = map(int, input().rstrip().split(' '))
player = list(map(int, input().rstrip().split(' ')))
if n <= k:
	k = n - 1
playWin = 0
count = 0
for i in range(1, n):
	tempComp = max(player[i], player[playWin])
	if player[playWin] == tempComp:
		count += 1
	else:
		count = 1
		playWin = i
	if count == k:
		break
print(player[playWin])


inp = list(map(int, input().split()))
games = inp[1]
players = list(map(int, input().split()))
best = players[0]
victory = 0
if games >= len(players) - 1:
	print(max(players))
else:
	for x in players[1:]:
		if x < best:
			victory += 1
		else:
			best = x
			victory = 1
		if victory == games:
			break
	print(best)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
prev = l[0]
c = 0
if k >= n - 1:
	print(max(l))
else:
	while c < k:
		if l[0] > l[1] and prev == l[0]:
			lost = l.pop(1)
			c = c + 1
			l.append(lost)
		elif l[0] < l[1] and prev == l[0]:
			prev = l[1]
			lost = l.pop(0)
			c = 1
			l.append(lost)
	print(prev)


import math
import os
import random
import re
import sys
pw = input().split()
p = int(pw[0])
w = int(pw[1])
powers = list(map(int, input().rstrip().split()[:p]))
x = 0
checker = []
if w > 1000:
	w = 1000
while len(checker) < w:
	if powers[x] > powers[x + 1]:
		checker.append(powers[x + 1])
		powers.append(powers[x + 1])
		del powers[x + 1]
	elif powers[x] < powers[x + 1]:
		powers.append(powers[x])
		del powers[x]
		checker.clear()
		checker.append(powers[x + 1])
print(powers[x])


(n, k) = input().strip().split()
n = int(n)
k = int(k)
day = 0
a = list(map(int, input().strip().split()))
score = 0
win = 0
if k >= n:
	print(n)
else:
	for i in range(2 * n):
		if i != 0:
			if a[win] > a[i]:
				a.append(i)
				score += 1
			else:
				a.append(win)
				win = i
				score = 1
			if score == k:
				print(a[win])
				break


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


from collections import deque

def find_winner(powers_array, required_number_of_straight_wins):
	if required_number_of_straight_wins > len(powers_array):
		required_number_of_straight_wins = len(powers_array)
	powers_queue = deque(powers_array)
	number_of_straight_wins = 0
	current_winning_power = powers_queue.popleft()
	while number_of_straight_wins < required_number_of_straight_wins:
		if current_winning_power < powers_queue[0]:
			powers_queue.append(current_winning_power)
			current_winning_power = powers_queue.popleft()
			number_of_straight_wins = 1
		else:
			powers_queue.append(powers_queue.popleft())
			number_of_straight_wins += 1
	return current_winning_power
input_players_wins = input().split(' ')
number_of_players = int(input_players_wins[0])
required_number_of_straight_wins = int(input_players_wins[1])
powers_array = [int(power) for power in input().split(' ')]
print(find_winner(powers_array, required_number_of_straight_wins))


firstLine = input().split(' ')
n = int(firstLine[0])
k = int(firstLine[1])
secondLine = input()
powerArr = [int(x) for x in secondLine.split(' ')]
firstMatchPlayed = 0
for x in range(n):
	playerStrength = powerArr[x]
	playerPos = x
	xcount = 0
	j = x + 1
	if j > n - 1:
		j = 0
	if firstMatchPlayed == 0:
		niter = k
	else:
		niter = k - 1
	while niter > 0:
		if powerArr[j] > playerStrength:
			break
		else:
			j += 1
			if j > n - 1:
				j = 0
		niter -= 1
		xcount += 1
		if xcount > n - 1:
			break
	firstMatchPlayed += 1
	if niter == 0 or xcount > n - 1:
		print(playerStrength)
		break


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = a[0]
temp = 0
if k >= n - 1:
	print(max(a))
else:
	while temp != k:
		(x, y) = (a[0], a[1])
		if x > y:
			a.append(y)
			del a[1]
		else:
			a.append(x)
			del a[0]
		if t == a[0]:
			temp += 1
		else:
			t = a[0]
			temp = 1
	print(a[0])


(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)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n - 1:
	print(n)
else:
	if a[1] > a[0]:
		index = 1
		max_value = a[1]
	else:
		index = 0
		max_value = a[0]
	for i in range(2, k):
		if a[i] > max_value:
			max_value = a[i]
			index = i
	for i in range(1, n):
		if i + k - 1 < n and a[i + k - 1] > max_value:
			max_value = a[i + k - 1]
			index = i + k - 1
		if index == i or (i == 1 and index == 0):
			break
	print(max_value)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
a = arr[0]
b = arr[1]
arr.pop(0)
arr.pop(0)
sumi = 0
if a > b:
	arr.append(b)
	maxp = a
	sumi += 1
else:
	arr.append(a)
	sumi += 1
	maxp = b
while 1:
	if sumi == n - 1 or sumi == k:
		print(maxp)
		break
	if max(maxp, arr[0]) == maxp:
		c = arr[0]
		arr.pop(0)
		arr.append(c)
		sumi += 1
	else:
		arr.append(maxp)
		maxp = arr[0]
		arr.pop(0)
		sumi = 1


from queue import Queue
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = Queue()
for i in a:
	q.put(i)
if k > n:
	print(max(a))
else:
	(best, pontos) = (q.get(), 0)
	while True:
		f = q.get()
		if best > f:
			pontos += 1
			q.put(f)
		else:
			q.put(best)
			(best, pontos) = (f, 1)
		if pontos >= k:
			print(best)
			break


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

def winner(person, k):
	winning = 0
	maxp = max(person)
	plaA = person.pop(0)
	plaB = person.pop(0)
	while winning < k:
		if plaA == maxp:
			break
		if plaA > plaB:
			winning += 1
			person.append(plaB)
		else:
			winning = 1
			person.append(plaA)
			plaA = plaB
		plaB = person.pop(0)
	return plaA
print(winner(person, k))


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()

def unique(sequence):
	seen = set()
	return [x for x in sequence if not (x in seen or seen.add(x))]
(n, k) = I()
a = list(I())
if k >= n:
	print(max(a))
	exit()
(i, j) = (0, 1)
w = [0] * (n + 1)
while True:
	if a[i] > a[j]:
		x = a[j]
		a.remove(x)
		a.append(x)
		w[a[i]] += 1
		if w[a[i]] == k:
			print(a[i])
			exit()
	else:
		x = a[i]
		w[a[j]] += 1
		if w[a[j]] == k:
			print(a[j])
			exit()
		a.remove(x)
		a.append(x)


(n, k) = map(int, input().split())
List = [int(x) for x in input().split()]
i = 1
t = 0
Max = List[0]
while i < n:
	X = max(Max, List[i])
	if X == Max:
		t += 1
	else:
		Max = X
		t = 1
	if t == k:
		break
	i += 1
print(Max)


(n, k) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
d = l[0]
t = 0
for i in range(1, n):
	if l[i] < d:
		t = t + 1
	else:
		t = 1
		d = l[i]
	if t == k:
		break
print(d)


nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
powers = list(map(int, input().split()))
p1 = powers.pop(0)
p2 = powers.pop(0)
w = 0
if k > 10000:
	k = 10000
while w < k:
	if p1 > p2:
		w += 1
		powers.append(p2)
		p2 = powers.pop(0)
	elif p1 < p2:
		powers.append(p1)
		p1 = p2
		p2 = powers.pop(0)
		w = 1
print(p1)


(n, k) = map(int, input().split())
powers = [int(i) for i in input().split()]
wins = {}
for i in powers:
	wins[i] = 0
i = 0
while True:
	if powers[0] == max(powers):
		print(powers[0])
		break
	if powers[0] > powers[1]:
		wins[powers[0]] += 1
		powers.append(powers[1])
		powers.pop(1)
		if wins[powers[0]] == k:
			print(powers[0])
			break
	else:
		wins[powers[1]] += 1
		powers.append(powers[0])
		powers.pop(0)
		if wins[powers[1]] == k:
			print(powers[1])
			break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n:
	print(max(a))
else:
	win_player = a[0]
	win_streak = 0
	for power in a[1:]:
		if win_player > power:
			win_streak += 1
		else:
			win_player = power
			win_streak = 1
		if win_streak == k:
			break
	print(win_player)


(n, k) = map(int, input().split())
v = list(map(int, input().split()))
occ = 0
pre = v[0]
for i in range(1, n):
	if pre > v[i]:
		occ += 1
	else:
		pre = v[i]
		occ = 1
	if occ == k:
		break
print(pre)


(n, k) = map(int, input().rstrip().split(' '))
players = list(map(int, input().rstrip().split(' ')))
if n <= k:
	k = n - 1
winner = 0
count = 0
for i in range(1, n):
	temp = max(players[i], players[winner])
	if players[winner] == temp:
		count = count + 1
	else:
		count = 1
		winner = i
	if count == k:
		break
print(players[winner])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
high = max(a.pop(0), a.pop(0))
try:
	if n == 2:
		raise IndexError
	while True:
		for i in range(k - 1):
			if a[i] > high:
				high = a[i]
				a = a[i + 1:]
				break
			elif i + 2 == k:
				raise IndexError
except IndexError:
	print(high)


(n, k) = [int(i) for i in input().split()]
list1 = [int(i) for i in input().split()]
if n == 2 or k > 10 ** 6:
	print(max(list1))
else:
	total = 0
	player = list1[0]
	waiter = list1[1:]
	while total < k:
		if player > waiter[0]:
			total += 1
			waiter = waiter[1:] + [waiter[0]]
		else:
			total = 1
			waiter = waiter[:] + [player]
			player = waiter[0]
			waiter = waiter[1:]
	print(player)


(n, k) = map(int, input().split())
players = list(map(int, input().split()))
flag = players[0]
winCount = k
i = 0
while winCount > 0:
	if k > len(players):
		maior = 0
		for i in range(len(players)):
			if players[i] > maior:
				maior = players[i]
		flag = maior
		break
	if flag == players[i]:
		i += 1
		continue
	elif flag > players[i]:
		aux = players[i]
		players.remove(aux)
		players.append(aux)
		winCount -= 1
	else:
		players.remove(flag)
		players.append(flag)
		winCount = k - 1
		flag = players[i - 1]
		i = 0
print(flag)


def main():
	(n, k) = map(int, input().split())
	tabT = list(map(int, input().split()))
	if k > n:
		print(max(tabT))
	else:
		won = [0] * n
		q = [x for x in range(n)]
		while won[q[0]] < k:
			t1 = tabT[q[0]]
			t2 = tabT[q[1]]
			if t1 > t2:
				won[q[0]] += 1
				q.append(q.pop(1))
			else:
				won[q[1]] += 1
				q.append(q.pop(0))
		print(tabT[q[0]])
main()


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, K) = map(int, input().split())
P = [int(x) for x in input().split()]
if K >= N - 1:
	print(max(P))
else:
	if P[0] > max(P[1:K + 1]):
		print(P[0])
		exit(0)
	for i in range(1, N):
		if P[i] > max(P[:i] or [float('-inf')]):
			tail = []
			p = P[0]
			for j in range(1, i):
				tail.append(min(p, P[j]))
				p = max(p, P[j])
			tail.append(p)
			tail = P[i + 1:] + tail
			if P[i] > max(tail[:K - 1]):
				print(P[i])
				exit(0)


from queue import Queue

def find_winner(q, n, k):
	p1 = q.get()
	c = 0
	while c < k:
		p2 = q.get()
		while c < k and p1 > p2:
			c += 1
			q.put(p2)
			p2 = q.get()
		if c >= k:
			return p1
		else:
			q.put(p1)
			p1 = p2
			c = 1
(n, k) = [int(num) for num in input().strip().split()]
q = Queue()
m = 0
for val in input().strip().split():
	m = max(m, int(val))
	q.put(int(val))
if n < k:
	print(m)
else:
	print(find_winner(q, n, min(n, k)))


(n, k) = [int(x) for x in input().split()]
power = [int(x) for x in input().split()]
achou = False
winner = 0
if k >= len(power):
	winner = max(power)
	achou = True
vitorias = 0
while not achou:
	if power[0] > power[1]:
		temp = power[0]
		power.append(power[1])
		power.pop(1)
	else:
		temp = power[1]
		power.append(power[0])
		power.pop(0)
	if winner == temp:
		vitorias += 1
	else:
		winner = temp
		vitorias = 1
	if vitorias == k:
		achou = True
print(winner)


(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
player = 0
mp = max(range(n), key=lambda i: nums[i])
while player < n:
	player1 = max(range(player, n), key=lambda i: nums[i] > nums[player])
	if player1 - player - (not player) >= k:
		print(nums[player])
		break
	if player1 == mp:
		print(nums[player1])
		break
	player = player1


from collections import deque
q = deque()
(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
if k >= n - 1:
	print(n)
else:
	for i in range(n):
		q.append(i)
	x = q.popleft()
	np = 0
	while np < k:
		y = q.popleft()
		if a[x] > a[y]:
			np += 1
			q.append(y)
		else:
			np = 1
			q.append(x)
			x = y
	print(a[x])


from sys import stdin

def sin():
	return stdin.readline()
(n, k) = map(int, sin().split())
p = list(map(int, sin().split(' ')))
ans = 0
for i in range(n):
	c = 0
	for j in range(i + 1, n):
		if p[i] > p[j]:
			c += 1
		else:
			break
	if i != 0 and p[i - 1] < p[i]:
		c += 1
	if c >= k:
		ans = p[i]
		break
if ans == 0:
	print(max(p))
else:
	print(ans)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
score = 0
x = 0
flag = False
while score != k:
	if arr[x] > arr[x + 1]:
		arr.append(arr[x + 1])
		arr.pop(x + 1)
		score += 1
		if flag == True:
			score += 1
		if arr[x] == max(arr):
			break
		flag = False
	else:
		score = 0
		flag = True
		arr.append(arr[x])
		arr.pop(x)
print(arr[x])


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
it = iter(a)
curr = -1
cnt = k
(x, y) = (next(it), next(it))
while cnt > 0:
	nxt = max(x, y)
	if nxt > curr:
		cnt = k
	curr = nxt
	cnt -= 1
	try:
		(x, y) = (curr, next(it))
	except StopIteration:
		break
print(curr)


inp = list(map(int, input().split()))
players = list(map(int, input().split()))
n = inp[0]
k = inp[1]
if n == 2:
	print(max(players[0], players[1]))
else:
	flag = False
	indice_prox = 2
	maior = max(players)
	num_vitorias = 0
	prev_vencedor = max(players[0], players[1])
	num_vitorias += 1
	if prev_vencedor == maior:
		print(prev_vencedor)
	else:
		while num_vitorias < k:
			prox = players[indice_prox]
			if prox == maior:
				flag = True
				print(maior)
				break
			vencedor = max(prev_vencedor, prox)
			if vencedor == prev_vencedor:
				num_vitorias += 1
			else:
				num_vitorias = 1
				prev_vencedor = vencedor
			indice_prox += 1
		if flag == False:
			print(prev_vencedor)


(n, k) = map(int, input().split())
z = k
a = list(map(int, input().split()))
if n - 1 <= k:
	print(max(a))
else:
	while k > 0:
		if a[0] > a[1]:
			(a[0], a[1]) = (a[1], a[0])
			l = a[0]
			a.pop(0)
			a.append(l)
			k -= 1
		else:
			l = a[0]
			a.pop(0)
			a.append(l)
			k = z - 1
	print(a[0])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k <= len(l):
	pos = l.index(max(l))
	h = l[:pos]
	m = 0
	i = 0
	j = 1
	while i < pos and j < pos and (m < k):
		if h[i] > h[j]:
			m += 1
			j += 1
		else:
			i = j
			j += 1
			m = 1
	if m >= k:
		print(h[i])
	else:
		print(max(l))
else:
	print(max(l))


def tennis(players, consWins, winCount):
	if consWins >= len(players) - 1:
		print(max(players))
	elif winCount == consWins:
		print(players[0])
	elif players[0] > players[1]:
		players = [players[i] for i in range(len(players)) if i != 1] + [players[1]]
		return tennis(players, consWins, winCount + 1)
	elif players[1] > players[0]:
		players = [players[i] for i in range(len(players)) if i != 0] + [players[0]]
		return tennis(players, consWins, 1)
nk = input().split()
n = int(nk[0])
k = int(nk[1])
players = input().split()
players = [int(players[i]) for i in range(n)]
tennis(players, k, 0)


pg = input().split()
p = int(pg[0])
g = int(pg[1])
l = list(map(int, input().rstrip().split()))
a = 0
count = 0
while count != g:
	a = int(l[0])
	b = int(l[1])
	if count > p:
		if a > b:
			count = g
		elif a < b:
			a = b
			count = g
	elif a > b:
		count += 1
		l.append(b)
		l.pop(1)
	elif a < b:
		l.pop(0)
		l.append(a)
		count = 1
print(a)


(n, k) = map(int, input().split())
data = list(map(int, input().split()))
if k > n - 2:
	print(n)
else:
	w = 0
	a = [0] * 501
	for j in range(1, n):
		if data[j] > data[w]:
			w = j
		a[w] += 1
		if a[w] >= k:
			print(data[w])
			break
	else:
		print(n)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
if k >= n - 1:
	print(max(a))
	exit(0)
while k not in b:
	if a[0] > a[1]:
		a.append(a[1])
		a.remove(a[1])
		b[a[0] - 1] += 1
	else:
		(a[0], a[1]) = (a[1], a[0])
		a.append(a[1])
		a.remove(a[1])
		b[a[0] - 1] += 1
print(b.index(k) + 1)


from math import *
(n, k) = [int(i) for i in input().split()]
gg = [int(i) for i in input().split()]
cnt = 0
comper = gg[0]
for i in range(1, len(gg)):
	if cnt >= k:
		print(comper)
		break
	if comper > gg[i]:
		cnt += 1
	else:
		comper = gg[i]
		cnt = 1
else:
	print(max(gg))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
winner = 0
h = 0
p = 0
for i in range(1, n):
	if arr[winner] > arr[i]:
		h += 1
		if h >= k:
			print(arr[winner])
			p = 1
			break
	else:
		winner = i
		h = 1
if p == 0:
	print(arr[winner])


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
if k >= n - 1:
	ans = n
else:
	i = 0
	cnt = 0
	ans = -1
	while i < n:
		if cnt == k:
			ans = arr[i]
			break
		for j in range(i + 1, n):
			if arr[i] > arr[j]:
				cnt += 1
				if cnt == k:
					ans = arr[i]
					break
			else:
				i = j
				cnt = 1
				break
		if ans != -1:
			break
		if i == n - 1:
			ans = n
			break
print(ans) if ans != -1 else print(n)


(n, k) = list(map(int, input().split()))
array = list(map(int, input().split()))
atak = 0
bb = array[0]
if max(array) < k:
	print(max(array))
	quit()
else:
	for i in range(n - 1):
		if bb < array[i + 1]:
			bb = array[i + 1]
			atak = 0
			atak += 1
		else:
			atak += 1
		if atak == k:
			print(bb)
			quit()
print(bb)


(g, f) = map(int, input().split())
mas = list(map(int, input().split()))
k = max(mas)
q = 0
n = mas[0]
for i in range(g):
	if mas[i] == k:
		print(mas[i])
		break
	if mas[i] > n:
		n = mas[i]
		q = 1
	elif i != 0:
		q += 1
	if q == f:
		print(n)
		break


import queue
(n, k) = map(int, input().split())
lista = list(map(int, input().split()))
p1 = lista[0]
p2 = lista[1]
q = queue.Queue()
for i in range(2, len(lista)):
	q.put(lista[i])
cnt = 0
while True:
	if p1 > p2:
		cnt += 1
		q.put(p2)
	else:
		q.put(p1)
		p1 = p2
		cnt = 1
	p2 = q.get()
	if cnt == k or cnt >= n:
		print(p1)
		break


from queue import Queue
import sys as os
(n, k) = map(int, input().split())
m = list(map(int, input().split()))
max = max(m)
q = Queue()
c = 0
el = m[0]
for i in m[1:]:
	if i == max:
		break
	if el > i:
		c += 1
	else:
		el = i
		c = 1
	if c == k:
		print(el)
		os.exit()
print(max)