def main():
n = int(input())
visited = [False] * n
nums = [i for i in range(1, n + 1)]
dfs(nums, visited, [])
def dfs(nums, visited, head):
if len(head) == len(nums):
print(' '.join(map(str ,head)))
for i in range(len(nums)):
if visited[i]:
continue
visited[i] = True
head.append(nums[i])
dfs(nums, visited, head)
head.pop()
visited[i] = False
main()