import sys
N = int(input())
#dest = list(map(int, sys.stdin.readline()[:-1].split(' ')))
perm = [i for i in range(1, N+1)]
result = []
def dfs():
if len(result) == N:
print(" ".join(map(str, result)))
return
for i in range(N):
if perm[i] not in result:
result.append(perm[i])
dfs()
result.pop()
dfs()