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