#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream input("hoanvi.inp");
ofstream output("hoanvi.out");

void print(vector <int> &sub)
{
	for (unsigned int i = 0; i < sub.size(); i++)
	{
		output << sub[i] << ' ';
	}
	output << '\n';
}

void hoanvi(vector <int> &sub)
{
	print(sub);
	unsigned int i, j;
	for (i = sub.size() - 2; i >= 0; i--)
	{
		if (sub[i] < sub[i + 1]) break;
		if (i == 0)
		{
			return;
		}
	}
	for (j = sub.size() - 1; j >= 0; j--)
	{
		if (sub[i] < sub[j])
		{
			swap(sub[i], sub[j]);
			break;
		}
	}
	reverse(sub.begin() + i + 1, sub.end());
	hoanvi(sub);
}
int main()
{
	int n;
	input >> n;
	vector <int> sub(n);
	for (unsigned int i = 0; i < n; i++)
	{
		sub[i] = i + 1;
	}
	hoanvi(sub);
	input.close();
	output.close();
	return 0;
}