#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 1; i <= n; ++i) {
        a[i - 1] = i;
    }
    do {
        for (int i = 0; i < n; ++i) {
            if (i == 0) cout << a[i];
            else cout << " " << a[i];
        }
        cout << endl;
    } while (next_permutation(a.begin(), a.end()));
}

