//acwing例题排列数字
#include <iostream>
using namespace std;
const int N=10;
int n;
int path[N];
bool st[N]; //判断该路径是否被走过
void dfs(int u)
{
if (u==n) //个数达到n个就可以输出
{
for (int i=0; i<n; i++) printf("%d",path[i]);
puts("");
return;
}
for (int i=1; i<=n; i++)
if (!st[i]) //如果st为false 该路径没走 那么向下遍历
{
path[u]=i;
st[i]=true;
dfs(u+1);
st[i]=false; //递归回溯
}
}
int main()
{
cin>>n;
dfs(0);
return 0;
}