#include <bits/stdc++.h>
using namespace std;

struct mset
{
    set<pair<int, int>> s;
    void del(int x)
    {
        auto br = s.upper_bound({x, -1});
        if(br->first == x) 
            if(br->second == 1) s.erase(br);
            else s.insert({x, br->second-1}), s.erase(br);
    }

    void add(int x)
    {
        auto br = s.upper_bound({x, -1});
        if(br->first != x) s.insert({x, 1});
        else s.insert({x, br->second+1}), s.erase(*br);
    }

    bool empty() { return s.empty(); }
    int  min() { return s.begin()->first; }

    friend ostream& operator << (ostream& os, mset& s)
    {
        for(auto& x : s.s) for(int i=0; i<x.second; i++) 
        os << x.first << " "; return os << endl; 
    }
};

void __msetTest()
{
    mset s = {{ {0, 3}, {1, 1}, {2, 1}, {3, 3}, {4, 1} }};
    cout << s;
    s.del(0);
    s.add(0);
    cout << s;
    cout << "min: " << s.min() << endl;
}


int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> sol, vec; mset s;
    int br; while(n--) cin >> br, vec.push_back(br);
    br = 0; int l=0, r=0; while(k>0)
    {
        //cout << "s before: " << s;
        for(int i=l;   i< br;   i++) s.del(vec[i]);
        for(int i=r+1; i<=br+k; i++) s.add(vec[i]);
        //cout << "s after : " << s;
        if(!s.empty()) sol.push_back(s.min()),
        //cout << "sol add : " << sol.back() << endl;
        l = br; r = br+k;
        while(vec[br] != sol.back())
            br++, k--; br++;
    }
    for(auto& x : sol) cout << x << " ";
    for(int i=br; i<vec.size(); i++) cout << vec[i] << " ";
    return cout << endl, 0;
}