#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++){
        t = i;
        temp = 1;
        while(t < N-1 && a[t] <= a[t+1]) {
            temp++;
            t++;
        }
        while((a.begin() + K + temp) - a.end() > 0){
            temp--;
        }
        a.erase(max_element(a.begin(), a.begin() + K + temp));
    }

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