#include<bits/stdc++.h>
using namespace std;
int main()
{
    ifstream fi("hoanvi.inp");
    ofstream fo("hoanvi.out");
    int64_t n, i, k, a, b;
    fi>>n;
    int64_t x[n+1];
    for(i=1;i<=n;i++)
    {
        x[i]=i;
    }
    do
    {
        for (i= 1;i<= n;i++)
        {
            fo<<x[i];
        }
        fo<<endl;
        i = n - 1;
        while ((i > 0)&& (x[i] > x[i + 1]))
        {
            i--;
        }
        if (i > 0)
        {
            k = n;
            while (x[k] < x[i]) k--;
            swap(x[k], x[i]);
            a= i + 1; b= n;
            while (a < b)
            {
                swap(x[a], x[b]);
                a++;
                b--;
            }
        }
    } while(i!=0);
}
