#include <bits/stdc++.h>

using namespace std;
int a[500010],seg[1100000];
int log2(int n)
{
    int res=0,i=1;
    while(i<n)
    {
        res++;
        i=i<<1;
    }
    return res;
}

void sagradi(int poz,int p,int k)
{
    if(p<=poz&&poz<=k)seg[poz]=poz-p+1;
    else if(poz>k)return;
    else
    {
        sagradi(2*poz,p,k);
        sagradi(2*poz+1,p,k);
        if(a[seg[2*poz]]<=a[seg[2*poz+1]])seg[poz]=seg[2*poz];
        else seg[poz]=seg[2*poz+1];
    }
}
int mini(int l,int r,int c,int d)
{
    if(c*(1<<d)>=l&&(c+1)*(1<<d)-1<=r)return seg[c];
    if(c*(1<<d)>r||(c+1)*(1<<d)-1<l)return 0;
    int pom1=mini(l,r,c<<1,d-1);
    int pom2=mini(l,r,(c<<1)+1,d-1);
    if(a[pom1]>a[pom2])return pom2;
    return pom1;
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int p=1<<log2(n);
    int kr=p+n-1;
    a[0]=INT_MAX;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sagradi(1,p,kr);
    int up=0,poz=1;
    while(n-poz>k-up&&up<n-k)
    {
        if(poz==k+up+1)
        {
            for(int i=poz;i<=n;i++)printf("%d ",a[i]);
            return 0;
        }
        poz=mini(poz+p-1,k+up+1+p-1,1,log2(p));
        printf("%d ",a[poz]);

        poz++;
        up++;

    }
    return 0;
}