#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=10005;
int n,a[maxn];
int Main()
{
freopen("martian.in","r",stdin);
freopen("martian.out","w",stdout);
int m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=m;++i)next_permutation(a+1,a+1+n);
for(int i=1;i<=n;++i)printf("%d ",a[i]);
return 0;
}
int main(){;}
int Bryant=Main();