#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int quanpailie( int* a , int k , int m )
{
if(k==m){
for(int i=0;i<=m;i++){
cout<<a[i]<<" ";
}
cout<<"\n";
}
else{
for(int i=k;i<=m;i++){
swap(a[k],a[i]);
quanpailie(a,k+1,m);
swap(a[k],a[i]);
}
}
}
int main()
{
int n;
int a[100];
cin>>n;
for(int i=0;i<n;i++){
a[i]=i+1;
}
quanpailie(a,0,n-1);
return 0;
}