import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n,k = map(int,input().split()) a = list(map(int,input().split())) p = [-1]*(n+1) q = deque([]) mx = n mn = 1 for i in range(n-1): q.append(i) if a[i] < a[i+1]: while q: p[mx] = q.pop() mx -= 1 if a[i] > a[i+1]: while q: p[mn] = q.popleft() mn += 1 q.append(n-1) for i in range(1, n+1): if p[i] == -1: p[i] = q.pop() ans = [] for i in range(n): if i == p[k]:continue ans.append(a[i]) print(*ans)