#include <bits/stdc++.h>

using namespace std;

void delOne(multiset<int>& s, int x) // not tested
{
    int br = s.count(x);
    s.erase(x);
    while(--br) s.insert(x);
}

void __testDelOne()
{
    multiset<int> s = {0, 1, 2, 3, 3, 3, 4};
    delOne(s, 3);
    for(auto& x : s) cout << x << " "; cout << endl;
}

ostream& operator << (ostream& os, multiset<int>& s)
{
    for(auto& x : s) os << x << " "; os << endl;
    return os;
}

int main()
{
    int n, k; cin >> n >> k;
    vector<int> sol, vec; multiset<int> s;
    int br; while(n--) cin >> br, vec.push_back(br);
    int l=0, r=-1; while(k)
    {
        int fr = r + 1; r = l + k; 
        for(int i=fr; i<=r; i++) s.insert(vec[i]); 
        //cout << "iter (" << l << ", " << r << ") ";
        sol.push_back(*s.begin());
        //cout << "sol.pb(" << sol.back() << ")" << endl;
        //cout << "k before: " << k << " set before: " << s;
        do delOne(s, vec[l]), l++, k--;
        while(k && vec[l] != sol.back());
        delOne(s, vec[l]), l++;
        //cout << "k after : " << k << " set after : " << s;
    }
    for(auto& x : sol) cout << x << " ";
    for(int i=l; i<vec.size(); i++) cout << vec[i] << " "; cout << endl;
    return 0;
}