r = []
n, m = map(int, input().split())
a = list(map(int, input().split()))
if m == n:
    for i in range(m):
        if a[0] >= a[-1]:
            max_a = a[0]  
            a.pop(0)
        else:
            max_a = a[-1]
            a.pop()
        r.append(max_a)
    print(" ".join(map(str, r)))