import sys
input=sys.stdin.readline
n,m=map(int,input().split())
s=[]
def dfs():
if len(s)==m:
print(' '.join(map(str,s)))
return
for i in range(1,n+1):
if i not in s:
s.append(i)
dfs()
s.pop()
dfs()
dfs의 재귀함수로 백트래킹을 구현할 수 있음
리스트 s에 있는 수열의 길이가 m이 되면 조건 만족으로 출력
for문으로 1부터 n까지 확인 후 s안에 들어있지 않으면 s에 추가
다시 dfs 호출, s.pop()
만약 n=4, m=2일 때 동작과정은 다음과 같음
s: 1 -> 1,2 -> 1 -> 1,3 -> 1 -> 1,4
pop(2) pop(3)