//Geeksun 2017.12.04
#include <iostream>
#include <cstring>
using namespace std;
int visit[11],num[11];
int n;
void dfs(int length)
{
if(length > n)
{
for(int i = 1;i <= n;i++)
{
cout << num[i] << " ";
}
cout << endl;
}
else
{
for(int i = 1;i <= n;i++)
{
if(visit[i] == 0)
{
visit[i] = 1;
num[length] = i;
dfs(length + 1);
visit[i] = 0;
}
}
}
}
int main()
{
cin >> n;
memset(visit,0,sizeof(visit));
dfs(1);
return 0;
}