#include<bits/stdc++.h>
#define maxn 500005
using namespace std;

int n,k;
int a[maxn];

int sol[maxn];


int najm[maxn][25];
void precalc()
{
    int lg=int(log2(n));
    for(int i=0;i<=lg;i++)
    {
        for(int j=0;j<n-(1<<i)+1;j++)
        {
            if(i==0)najm[j][i]=j;
            else{
                int minl=najm[j][i-1];
                int minr=najm[j+(1<<(i-1))][i-1];
                if(a[minl]<=a[minr])
                {
                    najm[j][i]=minl;
                }
                else
                {
                    najm[j][i]=minr;
                }
            }
        }
    }
}
int minn(int l,int r)
{
    int lg=int(log2(r-l+1));
    int minl=najm[l][lg];
    int minr=najm[r-(1<<lg)+1][lg];
    if(a[minl]<=a[minr])
    {
        return minl;
    }
    else
    {
        return minr;
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];

    precalc();

    /*int q;
    cin>>q;
    while(q>0)
    {
        int l,r;
        cin>>l>>r;
        cout<<minn(l,r)<<endl;
        q--;
    }*/

    int br=0;
    int pos=0;
    int dk=k;
    while(br<n-k)
    {
        int l=pos;
        int r=pos+dk;

        /*cout<<"sbr="<<br<<endl;
        cout<<"spos="<<pos<<endl;
        cout<<"sdk="<<dk<<endl;
        cout<<"l="<<l<<endl;
        cout<<"r="<<r<<endl;*/

        int minnn=minn(l,r);
        sol[br]=a[minnn];
        br++;
        dk-=minnn-pos;
        pos=minnn+1;

        /*cout<<"minnn="<<minnn<<endl;
        cout<<"nbr="<<br<<endl;
        cout<<"npos="<<pos<<endl;
        cout<<"ndk="<<dk<<endl;

        cout<<endl<<endl<<endl;*/
    }

    for(int i=0;i<n-k;i++)cout<<sol[i]<<" ";
    return 0;
}