#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;
typedef vector<pi> vp;
typedef vector<bool> vb;

vi sol;

int binarna(int k){
    int l = 0, r = sol.size(); --r;
    int mid = (l + r) / 2;

    int ind = INT32_MAX;
    while(l <= r){
        mid = (l + r) / 2;

        if (sol[mid] > k){
            ind = min(ind, mid);
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    return ind;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    int n, k;
    cin >> n >> k;

    vi a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    int cnt = 0;
    for (int i = 1; i < n; ++i){
//        m[a[i]] = i;

        sol.push_back(a[i]);
        if (a[i] <= a[i + 1] || cnt == k){
                continue;
        }

       // int ind = binarna(a[i + 1]);
      /*  for (int j = i; j >= ind; --j){
            if (cnt == k) break;

            sol.pop_back();
            ++cnt;
        }*/

        int cur = sol.size(); --cur;
        while(cur >= 0 && cnt < k && sol[cur] > a[i + 1]){
            sol.pop_back();
            --cur;
            ++cnt;
        }
    }
    sol.push_back(a[n]);
    while(cnt < k){
        sol.pop_back();
        ++cnt;
    }

    for (auto& i : sol)cout << i << ' ';
    cout << '\n';
}