#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX_N=100*1000;
void show(const vector<int>& V){
	for(int i=0;i<(int)V.size();i++)
		cout<<V[i]<<" ";
	cout<<endl;
}
vector<int> P;
int main()
{
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		P.push_back(i);
	sort(P.begin(),P.end());  // not needed here but remember to do it !
	do{
		show(P);
	}while(next_permutation(P.begin(),P.end()));
	return 0;
}