#include <iostream>
#include <fstream>
using  namespace std;
ifstream fi("hoanvi.inp");
ofstream fo("hoanvi.out");
long int n, kq[10000], dd[10000];

void xuat()
{
    for (int j=1; j<=n; j++)
        fo<< kq[j]<<" ";
    fo<< endl;
}

void backtrack(int i)
{
    if (i>n) xuat();
    for (int j=1; j<=n; j++)
        if (dd[j]==0)
        {
            dd[j]=1;
            kq[i]=j;
            backtrack(i+1);
            dd[j]=0;
        }
}

int main()
{
    fi >> n;
    for (int i=1; i<=9; i++)
        dd[i]=0;
    backtrack(1);
    return 0;
}
