#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,x[1000];
bool ok=true;
void init(){
	cin>>n;
	for(int i=0;i<n;i++){
		x[i]=i+1;
	}
}
void result(){
	for(int i=0;i<n;i++){
		cout<<x[i]<<" ";
	}
	cout<<endl;
}
void next_permutation(){
	int j=n-2;
	while(j>=0&&x[j]>=x[j+1]){
		j--;
	}
	if(j>=0){
		int k=n-1;
		while(x[k]<=x[j]){
			k--;
		}
		swap(x[j],x[k]);
		reverse(x+j+1,x+n);
	}
	else ok=false;
	
}
int main(){
init();
while(ok){
	result();
	next_permutation();
}
return 0;
}
