#include <cstdio>
int n;
int path[10];
bool st[10];
void dfs(int u) {
if(u == n + 1) {
for(int i = 1; i <= n; i++)
printf("%d ", path[i]);
puts("");
return ;
}
for(int i = 1; i <= n; i++) {
if(st[i]) continue;
st[i] = true;
path[u] = i;
dfs(u + 1);
st[i] = false;
}
}
int main (void) {
scanf("%d", &n);
dfs(1);
return 0;
}