#include <stdio.h>
#include <vector>
using namespace std;
vector<int> v;
int chunk[10], A;
void func() {
if(v.size() == A) {
for (int i=0 ; i < A ; i++)
printf("%d ", v[i]);
printf("\n");
return;
}
for (int i=1 ; i<=A ; i++) {
if(chunk[i] == 0) {
chunk[i] = 1;
v.push_back(i);
func();
chunk[i] = 0;
v.pop_back();
}
}
}
int main() {
scanf("%d", &A);
func();
}