BOJ 15651 NとM 3


import sys
sys.setrecursionlimit((10**5) // 2)

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

elem = [0] * (N+2)

def recur(idx):
	if idx >= M:
		print(' '.join(map(str, elem[:M])))
		return

	for i in range(1, N+1):
		elem[idx] = i
		recur(idx+1)
		elem[idx] = 0
recur(0)