n, m = map(int, input().split())
data = list(map(int, input().split()))
data.sort()
visited = [False] * n
out = []
def recur(k):
if k == m:
print(' '.join(map(str, out)))
return
overlap = 0
for i in range(n):
if not visited[i] and overlap != data[i]:
visited[i] = True
out.append(data[i])
overlap = data[i]
recur(k+1)
visited[i] = False
out.pop()
recur(0)