#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=10;
int main(){
int n;
cin>>n;
int a[N];
for(int i=1;i<=n;i++) a[i]=i;
do{
for(int i=1;i<=n;i++) printf("%d ",a[i]);
cout<<endl;
}while(next_permutation(a+1,a+n+1));
return 0;
}