#include <iostream>
using namespace std;
const int N = 9;
int n;
int ans[N];
bool is[N];
void f(int cnt)
{
if (cnt == n)
{
for (int i = 0; i < n; i ++ ) cout << ans[i] << ' ';
cout << endl;
return;
}
for (int i = 1; i <= n; i ++ )
{
if (!is[i])
{
is[i] = true;
ans[cnt] = i;
f(cnt + 1);
is[i] = false;
}
}
}
int main()
{
cin >> n;
f(0);
return 0;
}