#include <bits/stdc++.h>
using namespace std;
int p[10], v[10], n;
void dfs(int t) {
if (t > n) {
for (int i = 1; i <= n; ++i)
cout << p[i] << ' ';
cout << endl;
return;
}
for (int i = 1; i <= n; ++i) {
if (v[i] == 0) {
v[i] = 1;
p[t] = i;
dfs(t + 1);
v[i] = 0;
}
}
}
int main() {
cin >> n;
dfs(1);
return 0;
}