#include <iostream>
using namespace std;
const int N = 10;
int n;
int path[N]; //记录路径状态
bool st[N]; //表示当前数是否被使用过
void dfs(int u)
{
for (int i = 1; i <= n; i ++)
if(!st[i]) //如果当前数未被使用过
{
path[u]=i;
st[i]=true; //i已经被使用过了
dfs(u + 1);
st[i]=false;
}
if (u == n) //走到了第n个位置,开始输出
{
for (int i = 0 ;i < n; i ++) printf("%d ",path[i]);
puts("");
return;
}
}
int main()
{
cin >> n;
dfs(0);
return 0;
}