BOJ 15649 NとM 1


N, M = map(int, input().split())

## 1 based
check = [False] * (N+1)
elem = [0] * M
def recur(idx):
	
	if M == idx:
		for i in range(M):
			print(elem[i], end=' ')
		print()
		return

	for i in range(1, N+1):
		if check[i]:
			continue
		check[i] = True
		elem[idx] = i
		recur(idx+1)
		check[i] = False
	
recur(0)