#include<bits/stdc++.h>
using namespace std;
int a[10005],n,m;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
while(m--) next_permutation(a,a+n);
for(int i=0;i<=n-1;i++) printf("%d ",a[i]);
return 0;
}
next_permutation(a,a+n); //在a数组的基础上进行下一个全排列
PS:全排列的STL库的知识