n, k = map(int, input().split())
nums = list(map(int, input().split()))
import collections
stack = collections.deque()
res = []
for i in range(k):
while stack and stack[-1] < nums[i]:
stack.pop()
stack.append(nums[i])
res.append(stack[0])
for i in range(k, n):
if nums[i - k] == stack[0]:
stack.popleft()
while stack and stack[-1] < nums[i]:
stack.pop()
stack.append(nums[i])
res.append(stack[0])
print(*res)