#include<bits/stdc++.h>
using namespace std;
ifstream fi("HOANVI.inp");
ofstream fo("HOANVI.out");
int n;
int a[20];
void xuat(int x){
   for(int i=1;i<=x;++i)fo<<a[i];
   fo<<endl;
}
int main(){
      fi>>n;
   for(int i=1;i<=n;++i){
      a[i]=i;
      fo<<a[i];
   }
   fo<<endl;
   int t=n-1;
   while(t>0){
     t=n-1;
     while(a[t]>a[t+1])--t;
     if(t>0){
            int k=n;
         while(a[k]<a[t])k--;
         int tg=a[t];
     a[t]=a[k];a[k]=tg;
     sort(a+t+1,a+n);
     xuat(n);
     }
   }

}
