#include <bits/stdc++.h>

using namespace std;

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

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

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

void __testDelOne()
{
    mset s = {{0, 1}, {1, 1}, {2, 1}, {3, 3}, {4, 1}};
    cout << s;
    del(s, 3);
    add(s, 2);
    cout << s;
}
int main()
{
    int n, k; cin >> n >> k;
    vector<int> sol, vec; mset s;
    int br; while(n--) cin >> br, vec.push_back(br);
    int l=0, r=-1; while(13)
    {
        int fr = r + 1; r = l + k; 
        for(int i=fr; i<=r; i++) add(s, vec[i]); 
        //cout << "iter (" << l << ", " << r << ") ";
        if(!s.empty()) sol.push_back(s.begin()->first);
        //cout << "sol.pb(" << sol.back() << ")" << endl;
        //cout << "k before: " << k << " set before: " << s;
        do del(s, vec[l]), l++, k--;
        while(k && l<vec.size() && vec[l] != sol.back());
        if(l+1 >= vec.size() || k == 0) break;
        else del(s, vec[l]), l++;
        //cout << "k after : " << k << " set after : " << s;
    }
    for(auto& x : sol) cout << x << " ";
    for(int i=l+1; i<vec.size(); i++) cout << vec[i] << " ";
    return cout << endl, 0;
}