#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> tmp(n);
	for (int i = 0; i < n; ++i) tmp[i] = i + 1;
	do {
		cout << tmp[0];
		for (int i = 1; i < n; ++i) cout << ' ' << tmp[i];
		cout << endl;
	} while (next_permutation(tmp.begin(), tmp.end()));
}
