#include<bits/stdc++.h>

using namespace std;

#define llng long long

//#define DEBUG

llng A[500000];
bool T[500000];

llng n,k;

int main()
{
    priority_queue<pair<llng,llng> > heap;

    pair<llng,llng> tmp;

    cin >> n >> k;


    for (llng i=0LL;i<n;i++)
    {
        cin >> A[i];

        if (i<k+1)
        {
            #ifdef DEBUG
            cout << " > ADDING (" << A[i] << "," << i << ") TO HEAP!" << endl;
            #endif // DEBUG
            tmp.first=-A[i];
            tmp.second=i;
            heap.push(tmp);
        }

        T[i]=false;
    }

    llng r,ir;

    llng d=k+1LL;

    llng last=0LL;

    while(d<n)
    {
        while(heap.top().second < last)
        {
            #ifdef DEBUG
            cout << " > (" << heap.top().first << "," << heap.top().second << ") EXPIRED! " << endl;
            #endif // DEBUG

            heap.pop();
        }

        tmp = heap.top();
        r = -tmp.first;
        ir = tmp.second;
        heap.pop();

        T[ir]=true;
        last = ir;

        tmp.first = -A[d];
        tmp.second = d;
        heap.push(tmp);

        #ifdef DEBUG
        cout << " > FOUND (" << r << "," << ir << ")!" << endl;
        cout << " > ADDING (" << A[d] << "," << d << ") TO HEAP!" << endl;
        #endif // DEBUG


        d++;
    }

    while(heap.top().second < last)
    {
        #ifdef DEBUG
        cout << " > (" << heap.top().first << "," << heap.top().second << ") EXPIRED! " << endl;
        #endif // DEBUG

        heap.pop();
    }

    tmp = heap.top();
    r = -tmp.first;
    ir = tmp.second;
    heap.pop();

    T[ir]=true;

    #ifdef DEBUG
    cout << " > FOUND (" << r << "," << ir << ")!" << endl;
    #endif // DEBUG

    for (llng i=0LL;i<n;i++)
    {
        if (T[i])
            cout << A[i] << " ";
    }
}