n = int(input())
lt = [i+1 for i in range(n)]
st = [False] * n
cnt = 0
t = [0] * n
def dfs(lt,cnt,n,st):
if cnt == n:
print(' '.join(map(str,t)))
for idx, i in enumerate(lt):
if not st[idx]:
st[idx] = True
t[cnt] = i
cnt += 1
dfs(lt,cnt,n,st)
cnt -= 1
st[idx] = False
dfs(lt,cnt,n,st)