#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <utility>
#define MAXA 1000000009
using namespace std;
//pair<long long int,int> a[500005];
//pair<long long int,int> d[500005];
long long int aa[500005];
int pre[500005];
int pos[500005];
int y;
deque <long long int > q;
void resi(int p,int k)
{
    int i,j,t;
    /*for (i=0;i<y;i++) printf("%d ",pre[i]);
    printf("\n");
    for (i=0;i<y;i++) printf("%d ",pos[i]);
    printf("\n");*/
    if (k==0) return;
    if (pre[p]==-1)
    {
        if (aa[p]>aa[pos[p]])
        {
            //cout << aa[p] << " " << aa[pos[p]] << "\n";
            pre[p]=-2;
            pre[pos[p]]=-1;
            p=pos[p];
            k--;
            resi(p,k);
        }
        else resi(pos[p],k);
    }
    else if (pos[p]==-1)
    {
        if (aa[pre[p]]>aa[p])
        {

           /* pos[pre[p]]=-1;
            t=pre[p];
            pre[p]=-2;
            p=t;*/
            pos[pre[pre[p]]]=p;
            t=pre[p];
            pre[p]=pre[pre[p]];
            pre[t]=-2;

            k--;
            resi(p,k);

        }
        else return;
    }
    else
    {
        if (aa[pre[p]]>aa[p])
        {
            pos[pre[pre[p]]]=p;
            t=pre[p];
            pre[p]=pre[pre[p]];
            pre[t]=-2;

            k--;
            resi(p,k);
        }
        else if (aa[p]>aa[pos[p]])
        {
            t=pre[p];
            pre[p]=-2;
            pos[t]=pos[p];
            pre[pos[p]]=t;
            p=pos[p];
            k--;
            resi(p,k);
        }
        else resi(pos[p],k);
    }
}
int main()
{
    int n,i,j,k;
    int mini;
    //y=n;
    long long int mina;
    scanf("%d%d",&n,&k);
y=n;
   /* for (i=0;i<n;i++) scanf("%lld",&a[i].first),a[i].second=i,d[i].second=i,d[i].first=a[i].first;
    sort(d,d+n);
    int t=k;
    for (i=0;i<n;i++)
    {


    }*/
    /*if (n<=400)
    {
        for (i=0;i<n;i++) scanf("%lld",&aa[i]);
        mina=MAXA;

    }*/
    for (i=0;i<n;i++)
    {
        scanf("%lld",&aa[i]);



    }
    for(i=0;i<n-1;i++) pos[i]=i+1;
        for (i=1;i<n;i++) pre[i]=i-1;
        pos[n-1]=-1;
        pre[0]=-1;
    /*for(i=0;i<n;i++) cout << aa[i] << " ";
    cout << "\n";
    for(i=0;i<n;i++) cout << pre[i] << " ";
    cout << "\n";
    for (i=0;i<n;i++) cout << pos[i] << " ";
    cout << "\n";*/
    if (k==0)
    {

        for (i=0;i<n;i++) printf("%lld ",aa[i]);
        return 0;
    }
    resi(0,k);
    int p;
    for (i=0;i<n;i++) if (pre[i]==-1) j=i;
    p=j;
    while (true)
    {
        q.push_back(aa[p]);
        if (pos[p]==-1) break;
        p=pos[p];
    }
    for (i=0;i<n-k;i++) printf("%lld ",q.front()),q.pop_front();
    return 0;

}