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