#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int n;
    std::cin >> n;

    std::vector<int> A(n);
    for (int i = 0; i < n; i++) {
        A[i] = i + 1;
    }

    do {
        for (auto it = A.begin(); it < A.end(); it++) {
            if (it != A.begin()) std::cout << " ";
            std::cout << *it;
        }
        std::cout << std::endl;
    } while (std::next_permutation(A.begin(), A.end()));
}

