#include<iostream>
using namespace std;
int a,b,c,ans=0,f[10000000],g[10000000]={0},h[100000000];
void dfs(int x)
{if(x==0)
{for(int i=1;i<=c;i++)
{cout<<f[h[c+1-i]];
}
g[h[1]]=0;
cout<<endl;
ans=0;
}
else
{for(h[x]=1;h[x]<=b;h[x]++)
{if(g[h[x]]==1)
{continue;
}
g[h[x]]=1;
dfs(x-1);
g[h[x]]=0;
}
}
}
int main()
{
cin>>b;
for(int i=1;i<=b;i++)
{f[i]=i;
}
c=b;
dfs(b);
return 0;
}