#include<bits/stdc++.h>
using namespace std;
const int maxn=10000+5;
int n,m;
int a[maxn];
int Main(){
freopen("martian.in","r",stdin);
freopen("martian.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<m;i++)
next_permutation(a,a+n);
for(int i=0;i<n;i++){
printf("%d ",a[i]);
}
}
int main(){;}
int Avicii=Main();