#include <bits/stdc++.h>

using namespace std;

int n;
int k;
int a[500005];
vector<pair<pair<int,int>,int> > intervali;
bool obrisano[500005];
//0-rastuci
//1-opadajuci
//2-neutralni
vector<int> ve;
int l,r;

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

    cin >> n >> k;

    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }

    if(n==1)
    {
       cout << a[1];
       return 0;
    }

    int l=1;
    int r=2;

    int left=k;

    int ind2;

    int prev;
    int granica;
    int nxt;

    while(left>0)
    {
        //cout << l << " " << r << "\n";

        if(a[r]>=a[l])
        {
            //cout << "ovde 1" << "\n";
            prev=l;
            granica=r;
            while(r<=n && a[r]>=a[prev])
            {
                prev=r;
                r++;
            }

            r--;
            //cout << r << " " << granica << "\n";

            for(int i=r;i>=granica && left>0;i--)
            {
                obrisano[i]=true;
                i--;
                left--;
            }
        }
        else
        {
            //cout << "ovde 2" << "\n";
            nxt=r+1;
            while(nxt<=n && a[l]>=a[nxt] && left>0)
             {
                 obrisano[l]=true;
                 l=nxt;
                 nxt++;
                 left--;
             }
             r=nxt;
        }
    }


    for(int i=1;i<=n;i++)
    {
        if(!obrisano[i]) cout << a[i] << " ";
    }

    /*l=1;
    for(int i=2;i<=n;)
    {
        if(a[i]>=a[i-1])
        {
            while(i<=n && a[i]>=a[i-1])
               i++;

            i--;
            r=i;
            intervali.push_back({{l,r},0});
        }
        else if(a[i]<=a[i-1])
        {
            while(i<=n && a[i]<=a[i-1])
               i++;

            i--;
            r=i;
            intervali.push_back({{l,r},1});
        }

        l=r+1;
        i=r+2;
    }

    int left=k;

    for(int i=0;i<intervali.size();i++)
    {
        pair<pair<int,int>,int> pa=intervali[i];
        //cout << pa.first.first << " " << pa.first.second << " " << pa.second << "\n";

        if(pa.second==0)
        {

        }

    }*/



    return 0;
}