n, m = map(int, input().split())
state = [0] * n
used = [0] * n
tag = 0
def dfs(u, tag):
if u == m:
for i in range(m):
print(state[i], end = " ")
print()
return
for i in range(tag , n):
if not used[i]:
state[u] = i + 1
used[i] = True
tag = i
dfs(u + 1, tag)
state[u] = 0
used[i] = False
dfs(0, tag)
tag=i+1 就可以省去used数组了