#include <fstream>
#include <bitset>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
const int nMax = 8 + 2;
int n;
int r[nMax];
bitset < nMax > ap;
void Write()
{
for (int i = 1; i <= n; i++)
{
fout << r[i] << ' ';
}
fout << '\n';
}
void Permutari(int pos)
{
if (pos == n + 1)
{
Write();
return;
}
for (int i = 1; i <= n; i++)
{
if (!ap[i])
{
ap[i] = 1;
r[pos] = i;
Permutari(pos + 1);
ap[i] = 0;
}
}
}
int main()
{
fin >> n;
Permutari(1);
fin.close();
fout.close();
return 0;
}