#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int state[10];
bool used[10];
void dfs(int u)
{
if (u > n)
{
for (int i = 1; i <= n; i++)
printf("%d ", state[i]);
puts("");
return;
}
for (int i = 1; i <= n; i++)
if (!used[i])
{
state[u] = i;
used[i] = true;
dfs(u + 1);
state[u] = 0; // 恢复现场
used[i] = false;
}
}
int main()
{
scanf("%d", &n);
dfs(1);
return 0;
}