import sys
sys.setrecursionlimit((10**5))
N, M = map(int, input().split())
elem = list(map(int, input().split()))
elem.sort()
check = [0] * N
ans = [0] * N
def recur(depth):
if depth == M:
print(' '.join(map(str, ans[:M])))
return
for i in range(N):
ans[depth] = elem[i]
recur(depth+1)
ans[depth] = 0
recur(0)