#include <iostream>
using namespace std;
int n;
bool st[17];
int ans[17];
void dfs(int u){
if(u == n+1){
for (int i = 1; i <= n; i ++ ) cout << ans[i] << ' ';
cout << endl;
return;
}
for (int i = 1; i <= n; i ++ ){
if(!st[i]){
st[i] = 1;
ans[u] = i;
dfs(u+1);
st[i] = 0;
}
}
}
int main(){
cin >> n;
dfs(1);
return 0;
}