#include <bits/stdc++.h>
#define MAXN 524288
#define ulli unsigned long long int
using namespace std;
ulli a[MAXN];
ulli n,y=1;

ulli seg[4*MAXN];

void lezaja(ulli idx)
{
    if(idx>=y){seg[idx]=idx-y;return;}
    lezaja(2*idx);
    lezaja(2*idx+1);
    seg[idx]=(a[seg[2*idx]]<=a[seg[2*idx+1]])?seg[2*idx]:seg[2*idx+1];
}

ulli hitova(ulli l0,ulli r0,ulli idx,ulli l,ulli r)
{
    if(idx>=y)return idx-y;
    ulli s = (l0+r0)/2;
    if(l==l0 && r==r0)return seg[idx];
    if(r<=s)return hitova(l0,s,2*idx,l,r);
    if(l>s)return hitova(s+1,r0,2*idx+1,l,r);

    ulli v = hitova(l0,s,2*idx,l,s);
    ulli w = hitova(s+1,r0,2*idx+1,s+1,r);
    return (a[v]<=a[w])?v:w;

}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    cin>>n;
    ulli k;
    cin>>k;
    for(ulli i=0;i<n;i++)cin>>a[i];
    ulli pos=0;
    while(y<n)y*=2;
    lezaja(1);

    ///for(ulli i=0;i<2*y;i++)cout<<seg[i]<<" ";
    ///cout<<endl;

    ///cout<<hitova(0,7,1,1,3);

    while(pos<n-k)
    {
        ///cout<<pos<<k<<endl;
        if(k==0) {for(ulli i=pos;i<n;i++)cout<<a[i]<<" ";break;}
        ulli minpos = pos;
        ///for(ulli i=pos;i<=pos+k  && i<n;i++) if(a[i]<a[minpos])minpos=i;
        minpos=hitova(0,y-1,1,pos,pos+k);
        ///cout<<minpos<<endl;
        cout<<a[minpos]<<" ";
        k-=minpos-pos;
        pos=minpos+1;
    }
    return 0;
}

/**
4 1
4 8 6 3

8 3
6 0 3 1 4 2 1 7

5 2
1 2 3 4 5
*/