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

    llng najveci=0;
    llng najmanji=0;
    llng brjed=0;

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

        if (A[i]>najveci) najveci=A[i];
        if (A[i]<najmanji) najmanji=A[i];
        if (A[i]==1) brjed++;

        if (i<k+1LL)
        {
            #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;
    }

    if (najveci==1 && najmanji==0)
    {
        int br=k;

        if (brjed<=k)
        {
            for (int i=0;i<n-k;i++)
            {
                cout << "0 ";
            }
            return 0;
        }
        else
        {
            for (int i=0;i<n;i++)
            {
                if (A[i]==1 && br>0)
                {
                    br--;
                }
                else
                {
                    cout << A[i] << " ";
                }
            }
            return 0;
        }
    }

    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] << " ";
    }

    return 0;
}