#include <iostream>
#include <vector>
using namespace std;
const int N = 10;
vector<int> res;
int n;
void dfs(int t, int state){
if(t == n){
for(int i = 0; i < n; i ++ ){
cout << res[i];
if(i != n-1) cout << " ";
else cout << endl;
}
return ;
}
for(int i = 0; i < n; i ++ ){
if(state >> i & 1) continue;
res.push_back(i+1);
dfs(t+1, state|(1 << i));
res.pop_back();
}
}
int main(){
cin >> n;
dfs(0, 0);
return 0;
}