#include<iostream>
using namespace std;
const int N = 10;
int n;
int path[N];
bool st[N];
void dfs(int u)
{
if(u == n) //一个分支走到头
{
for (int i = 0; i < n; i ++ ) printf("%d ",path[i]); //分别输出分支的每一个数
cout << endl;
return ;
}
for (int i = 1; i <= n; i ++ )
{
if(!st[i]) //这个数没有被用过
{
path[u] = i; //没有用过那么按顺序填上
st[i] = true;
dfs(u + 1);
st[i] = false; //回溯
}
}
}
int main()
{
cin >> n;
dfs(0);
return 0;
}