#include <bits/stdc++.h>using namespace std;int main(int argc, char** argv){int a;while(cin>>a){int b[a];for(int c=0;c<a;c++)b[c]=a-c;do{for(int c=0;c<a;c++)cout<<b[c];cout<<endl;}while(prev_permutation(b,b+a));}}