#include <cstdlib>
#include <cstdio>
#define gr 500010
int a[gr];
int l[gr];
int naz[gr];
int b[gr];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i)scanf("%d",a+i);
    l[0]=-1;
    for(int i=1;i<n;++i)
    {
        int m=i-1;
        while((m>=0)&&(a[m]>a[i]))m=l[m];
        l[i]=m;
    }
    for(int i=0;i<n;++i)naz[i]=-1;
    int bi=0;
    int vrh=0;
    int pr;
    int d;
    for(int p=k;true;++p)
    {
        pr=-1;
        for(int i=p;true;)
        {
            if(i<vrh)
            {
                vrh=pr;
                break;
            }
            if(naz[i]!=-1)
            {
                naz[i]=pr;
                break;
            }
            naz[i]=pr;
            pr=i;
            i=l[i];
            if(i==-1)
            {
                vrh=pr;
                break;
            }
        }
        b[bi++]=a[vrh];
        vrh=naz[vrh];
        if(vrh==-1)
        {
            d=p+1;
            break;
        }
    }
    for(int i=d;i<n;++i)b[bi++]=a[i];
    if(bi>n-k)bi=n-k;
    for(int i=0;i<bi;++i)printf("%d ",b[i]);
    printf("\n");
    return 0;
}