#include<bits/stdc++.h>
using namespace std;
int n,a[13],book[13];
void dfs(int x)
{
if(x>n)
{
for(int i=1;i<=n;i++)
cout<<" "<<a[i];
cout<<endl;
return;
}
for(int i=1;i<=n;i++)
{
if(book[i]==0)
{
book[i]=1;
a[x]=i;
dfs(x+1);
a[x]=0;
book[i]=0;
}
}
}
int main()
{
cin>>n;
dfs(1);
}