#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
while ( cin >> n ) {
vector <int> perm;
for ( int i = n; i > 0; --i )
perm.push_back ( i );
do {
for ( int i = 0; i < perm.size(); ++i )
cout << perm[i];
cout << endl;
} while ( prev_permutation ( perm.begin(), perm.end() ) );
}
return 0;
}