#include <bits/stdc++.h>


using namespace std;
ifstream f1("hoanvi.inp");
ofstream f2("hoanvi.out")
int n,a[1000];
vector <int> d(1000,0);
void kq()
{ int i;
    for ( i=1;i<=n;i++)
    { f2<<a[i]<<" ";}
    f2<<endl;
}
void hoanvi(int i)
{ int j;
    for ( j=1;j<=n;j++)
    { if (d[j]==0)
        {a[i]=j;
        d[j]=1;
        if (i==n) {kq();}
        else {hoanvi(i+1);} d[j]=0;}

    }
}
int main()
{
    f1>>n;
    hoanvi(1);
   return 0;
}
