import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 n, k = mi() a = li() p = [-1] * n q = [] l = 0 r = n - 1 for i in range(n-1): q.append(i) if a[i] == a[i+1]: continue if a[i] < a[i+1]: while q: p[r] = q.pop() r -= 1 if a[i] > a[i+1]: while q: p[l] = q.pop() l += 1 q.append(n-1) while q: p[l] = q.pop() l += 1 ans = [] for i in range(n): if i == p[k-1]: continue ans.append(a[i]) print(*ans)