N, K = map(int, input().split()) A = list(map(int, input().split())) order = [] minimum = 1 maximum = N i = 0 while i < N - 1: if A[i] < A[i + 1]: order.append(maximum) maximum -= 1 elif A[i] > A[i + 1]: order.append(minimum) minimum += 1 else: j = i + 1 while A[i] == A[j]: j += 1 for _ in range(j - i): if A[i] < A[j]: order.append(maximum) maximum -= 1 else: order.append(minimum) minimum += 1 i = j i += 1 order.append(maximum) for i in range(N): if order[i] != K: print(f"{A[i]}", end = " ")