#include <iostream>
using namespace std;
const int N = 10;
bool st[N];
int path[N];
int n;
void dfs(int u){
    if(u == n){
        for(int i = 0;i < n;i++){
            cout << path[i] << " ";
        }
        cout << endl;
    }
    for(int i = 1;i<=n;i++){
        if(!st[i])
        {
            path[u] = i;
            st[i] = true;
            dfs(u+1);
            path[u] = 0;
            st[i] = false;
        }
    }
}
int main(void) {
    cin >> n;
    dfs(0);
}