#include
#include
using namespace std;
const int N=1e4+10;
int a[N];
int main()
{
//freopen("in.txt","r",stdin);
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
while(m--)next_permutation(a+1,a+n+1);
for(int i=1;i<=n;i++)printf("%d%c",a[i],i==n?'\n':' ');
return 0;
}
STL大法好