#include <iostream>
using namespace std;
int n, k, arr[200005];
void quicksort(int lo, int hi, int sign) {
int i,j,m;
i = lo;
j = hi;
m = arr[(lo+hi)>>1];
while(i<=j) {
while(sign * arr[i] < m * sign) i++;
while(sign * arr[j] > m * sign) j--;
if(i<=j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}
if(lo<j) quicksort(lo,j, sign);
if(i<hi) quicksort(i,hi, sign);
}
int main() {
cin>>n>>k;
for(int i = 0; i < n; ++i) {
cin>>arr[i];
}
quicksort(0, k-1, 1);
quicksort(k, n, -1);
for (int i = 0 ; i < n ; i ++) cout << arr[i] << " ";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBuLCBrLCBhcnJbMjAwMDA1XTsKdm9pZCBxdWlja3NvcnQoaW50IGxvLCBpbnQgaGksIGludCBzaWduKSB7CiAgICAKICAgICBpbnQgaSxqLG07CiAgICAgaSA9IGxvOwogICAgIGogPSBoaTsKICAgICBtID0gYXJyWyhsbytoaSk+PjFdOwogICAgCiAgICAgd2hpbGUoaTw9aikgewogICAgICAgICB3aGlsZShzaWduICogYXJyW2ldIDwgbSAqIHNpZ24pIGkrKzsKICAgICAgICAgd2hpbGUoc2lnbiAqIGFycltqXSA+IG0gKiBzaWduKSBqLS07CiAgICAgICAgIGlmKGk8PWopIHsKICAgICAgICAgICAgaW50IHRlbXAgPSBhcnJbaV07CiAgICAgICAgICAgIGFycltpXSA9IGFycltqXTsKICAgICAgICAgICAgYXJyW2pdID0gdGVtcDsKICAgICAgICAgICAgaSsrOwogICAgICAgICAgICBqLS07CiAgICAgICAgIH0gICAgICAgIAogICAgIH0KICAgIAogICAgIGlmKGxvPGopIHF1aWNrc29ydChsbyxqLCBzaWduKTsKICAgICBpZihpPGhpKSBxdWlja3NvcnQoaSxoaSwgc2lnbik7CiAgICAgCn0KCmludCBtYWluKCkgewogICAgCiAgICBjaW4+Pm4+Pms7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgY2luPj5hcnJbaV07CiAgICB9IAogICAgCiAgICBxdWlja3NvcnQoMCwgay0xLCAxKTsKICAgIHF1aWNrc29ydChrLCBuLCAtMSk7CiAgICAKICAgIGZvciAoaW50IGkgPSAwIDsgaSA8IG4gOyBpICsrKSBjb3V0IDw8IGFycltpXSA8PCAiICI7Cn0=