#include <algorithm>
#include <iostream>
#include <fstream>
using namespace std;
const int MAXN(10001);
int n, m, s[MAXN];
ifstream fin("martian.in");
ofstream fout("martian.out");
#define cin fin
#define cout fout
main()
{
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> s[i];
fin.close();
for (int i = 0; i < m; ++i)
next_permutation(s + 1, s + n + 1);
for (int i = 1; i <= n; ++i)
cout << s[i] << ' ';
fout.close();
// for(;;);
}