#include <iostream>
#include <algorithm>
#include <vector>
int main() {
int n, k;
std::cin >> n >> k;
std::vector<int> v(n);
for (int i = 0; i < n; ++i) {
std::cin >> v[i];
}
while (k--) {
std::next_permutation(v.begin(), v.end());
}
for (int i: v) {
std::cout << i << ' ';
}
return 0;
}