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

void print(int a[], int n){
    for(int i=0; i<n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

int main(){
    int n;
    cin >> n;
    int a[11];
    for(int i=0; i<n; i++){
        a[i] = i+1;
    }
    do {
        print(a, n);
    } while (next_permutation(a, a+n));
    return 0;
}
