#include <iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

int mg[500006],r[500005],sg[2000000];


void nsg(int cvor,int l,int d)
{
    int s=(l+d)/2;

    if(l==d) sg[cvor]=mg[l];
    else
    {
       nsg(2*cvor,l,s);
       nsg(2*cvor+1,s+1,d);
       sg[cvor]=min(sg[2*cvor],sg[2*cvor+1]);
    }
}

int resi(int cvor,int l,int d,int x,int y)
{
    int s=(l+d)/2,rrr=1000000009;

    if(x<=l && y>=d) return sg[cvor];
    else
    {
        if(x<=s) rrr=min(rrr,resi(2*cvor,l,s,x,y));
        if(y>s) rrr=min(rrr,resi(2*cvor+1,s+1,d,x,y));
        return rrr;
    }
}



int main()
{
    ios::sync_with_stdio(false);

    int n,k,i,j,a,b,x,t,p,ddd;

    cin>>n>>k;
    for(i=1;i<=n;i++) cin>>mg[i];

    nsg(1,1,n);


    p=0;
    for(i=1;i<=n-k;i++)  //trazimo itog u novom nizu
    {
        ddd=min(n,k+i);
        t=resi(1,1,n,p+1,ddd);

        for(j=p+1;j<=n;j++)
        {
            if(mg[j]==t) {r[i]=t; p=j; break;}
        }
    }


    for(i=1;i<=n-k;i++) cout<<r[i]<<" ";

    /*
    8 3
    6 0 3 1 4 2 1 7
    */


    return 0;
}