#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)
{
    //cout<<l<<" "<<r<<" "<<c<<" "<<d<<endl;
    if(c*(1<<d)>=l&&(c+1)*(1<<d)-1<=r)
    {
        //cout<<"Usao! "<<c<<endl;
        return seg[c];
    }
    if(c*(1<<d)>r||(c+1)*(1<<d)-1<l)
    {
        //cout<<"Izasao! "<<c<<endl;
        return 0;
    }
    int pom1=mini(l,r,c<<1,d-1);
    int pom2=mini(l,r,(c<<1)+1,d-1);
    //cout<<pom1<<" "<<pom2<<endl;
    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]=1000000001;

    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    if(k==0)
    {
        for(int i=1;i<=n;i++)printf("%d ",a[i]);
        return 0;
    }
    if(k==1)
    {
        int pom=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]<a[i+1])printf("%d ",a[i]);
            else
            {
                pom=i+1;
                break;
            }
        }
        for(int i=pom;i<=n;i++)printf("%d ",a[i]);
        return 0;
    }
    if(k==n-1)
    {
        sagradi(1,p,kr);
        printf("%d",a[seg[1]]);
        return 0;
    }

    sagradi(1,p,kr);
    int up=0,poz=1;
    //cout<<mini(3+p-1,5+p-1,1,log2(p));

    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;
        }
        //cout<<poz<<" "<<k+up+1<<":";
        poz=mini(poz+p-1,k+up+1+p-1,1,log2(p));
        printf("%d ",a[poz]);
        //cout<<endl;
        //cout<<poz<<endl;
        poz++;
        up++;
    }
    if(up<n-k)for(int i=poz;i<=n;i++)printf("%d ",a[i]);
    return 0;
}
/*
8 3
6 0 3 1 4 2 1 7
*/