#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

vector<int> a;
int N, K;

int main()
{
    cin >> N >> K;
    int f;
    for(int i = 0; i < N; i++){
        cin >> f;
        a.push_back(f);
    }
    int temp = 1, t = 0;
    for(int i = 0; i < K; i++){
        if(t < N-1 && a[t] <= a[t+1]) {
            //cout << a[t] << "je manje ili jednako od" << a[t+1] << "\n";
            temp++;
            t++;
        }
        //cout << "temp je = " << temp << "\n";
        //cout << "Gleda prvih elemenata:" << a.end() - (a.begin() + K + temp) << "\n";
        while((a.begin() + K + temp) - a.end() > 0){
            temp--;
        }
        //cout << *max_element(a.begin(), a.begin() + K + temp) << "=Max element\n";
        a.erase(max_element(a.begin(), a.begin() + K - i + temp));
    }

    for(int i = 0; i < a.size(); i++){
        cout << a[i] << " ";
    }
    return 0;
}