#include <bits/stdc++.h>

using namespace std;

void nearest_neighbour_secenje_sa_ogranicenjem(int* arr, int n, int k){

    int i = 0;

    int cleanamount = k;

    stack<int> stek;

    while (arr[i] < arr[i+1]){
        stek.push(i);
        i++;
    }

    for ( ; i < n; i++){

        while(!stek.empty() && cleanamount > 0 && arr[stek.top()] > arr[i]){
            stek.pop();
            cleanamount--;
        }

        stek.push(i);

    }

    while (cleanamount > 0){
        stek.pop();
        cleanamount--;
    }

    int newarr[n-k];

    for (int j = n-(k+1); j >= 0; j--){
        newarr[j] = arr[stek.top()];
        stek.pop();
    }

    for (int j = 0; j < n-k; j++){
        cout << newarr[j] << " ";
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);

    //kucaj ovdekaj

    //nearest neighbour verovatno
    int n, k;

    cin >> n >> k;

    int arr[n];

    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }

    nearest_neighbour_secenje_sa_ogranicenjem(arr, n, k);
    //cout << "a";

    return 0;
}