#include <iostream>
#include <vector>
using namespace std;
const int N = 15;
bool used[N];
int path[N];
int n;
void dfs(int c) {
if (c == n) {
for (int i = 0; i < n; ++i) {
cout << path[i] << ' ';
}
cout << endl;
return;
}
for (int i = 0; i < n; ++i) {
if (used[i]) {
continue;
}
path[c] = i + 1;
used[i] = true;
dfs(c + 1);
used[i] = false;
}
}
int main() {
cin >> n;
dfs(0);
return 0;
}