#include <bits/stdc++.h>
using  namespace std;
int n, kq[11], dd[10];
ifstream f1("HOANVI.INP");
ofstream f2("HOANVI.OUT");
void xuat()
{
    for (int j=1; j<=n; j++)
        cout<< kq[j]<<" ";
    f2 << 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()
{
    f1 >> n;
    for (int i=1; i<=9; i++)
        dd[i]=0;
    backtrack(1);
    f1.close();
    f2.close();
}
