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

int seg[4*MAXN];

void lezaja(int 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];
}

int hitova(int l0,int r0,int idx,int l,int r)
{
    if(idx>=y)return idx-y;
    int 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);

    int v = hitova(l0,s,2*idx,l,s);
    int 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;
    int k;
    cin>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    int pos=0;
    while(y<=n)y*=2;
    lezaja(1);

    ///for(int 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(int i=pos;i<n;i++)cout<<a[i]<<" ";break;}
        int minpos = pos;
        ///for(int 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
*/