#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;

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);
    for (auto& i : a)
        cin >> i;

    vp s;
    int cnt = 1;
    a.push_back(-1);
    for (int i = 0; i < n; ++i){
        if (a[i] != a[i + 1]){
            s.push_back({a[i], cnt});
            cnt = 1;
        } else {
            ++cnt;
        }
    }

    int m = s.size();
    cnt = 0;
    for (int i = 0; i < m - 1; ++i){
        if (cnt == k) break;

        if (s[i].first > s[i + 1].first){
            int l = k - cnt;
            int d = min(l, s[i].second);

            cnt += d;
            s[i].second -= d;
        }
    }

    int j = m - 1;
    while(cnt < k){
        int d = min(k - cnt, s[j].second);
        cnt += d;
        s[j].second -= d;
    }

    for (auto& i : s){
        for (int c = 0; c < i.second; ++c){
            cout << i.first << ' ';
        }
    }

    cout << '\n';
}