#include<bits/stdc++.h>
using namespace std;
const int N=25;
int a[N];
bool st[N];
int n;
void dfs(int depth){
if(depth==n+1){
for(int i=1;i<=n;i++)
printf("%d ",a[i]);
puts("");
}
for(int i=1;i<=n;i++){
if(!st[i]){
a[depth]=i;
st[i]=true;
dfs(depth+1);
st[i]=false;
}
}
}
int main(){
cin>>n;
dfs(1);
return 0;
}