#include <iostream>
using namespace std;
const int N = 10;
int n, path[N];
bool st[N];
void dfs(int x)
{
if (x == n)
{
for (int i = 0; i < n; i ++ ) printf("%d ", path[i]);
printf("\n");
return;
}
for (int i = 1; i <= n; i ++ )
{
if(!st[i])
{
path[x] = i;
st[i] = 1;
dfs(x + 1);
st[i] = 0;
path[x] = 0;
}
}
}
int main()
{
cin >> n;
dfs(0);
return 0;
}