import sys from collections import deque, Counter sys.setrecursionlimit(5 * 10 ** 5) from pypyjit import set_param set_param('max_unroll_recursion=-1') 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 def solve(n, k, p): top = [] bottom = [] same = [] p.append(0) for i in range(n): if p[i] < p[i + 1]: top.append(i) for v in same: top.append(v) same = [] elif p[i] > p[i + 1]: bottom.append(i) for v in same: bottom.append(v) same = [] else: same.append(i) q = top + bottom[::-1] ind = q[n - k] ans = [] for i in range(n): if i == ind: continue ans.append(p[i]) p.pop() return ans def solveg(n, k, a): X = [] for i in range(n): x = [] for j in range(n): if i == j: continue x.append(a[j]) X.append(x) X.sort() print(X) return X[k - 1] n, k = mi() a = li() print(*solve(n, k, a))