n = int(input())
state = [0 for i in range(n+1)]
used = [0 for i in range(n+1)]
def dfs(s, n, state, used):
if s > n:
print(' '.join(map(str, state[1:])))
else:
for i in range(1, n+1):
if used[i] == 0:
state[s] = i
used[i] = 1
dfs(s+1, n, state, used)
# state[s] = 0
used[i] = 0
dfs(1, n, state, used)