#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int x;
while (cin >> x)
{
int a[] = { 1,2,3,4,5,6,7,8 };
sort(a, a + x);
reverse(a, a + x);
do
{
for (int i = 0; i < x; i++)
{
cout << a[i];
}
cout << "\n";
} while (prev_permutation(a, a + x));
}
}