#include <iostream>
#include <set>
#include <deque>
#define N 500005

using namespace std;

int n, k;
int niz[N]={};
deque <int> lol;
int pok=0;

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

    cin>>n>>k;

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

    int kkk=k;
    int gran = n-k-1;
    int oldgran = 1;

    while(kkk--)
    {
        //lol.push_front(niz[1]);

        //cout<<"front "<<lol.front()<<endl;

        for(int i=oldgran;i<=gran;i++)
        {
            while(lol.size() && niz[i]<lol.front())
            {
                //cout<<"izbaci "<<lol.front()<<endl;
                lol.pop_front();
            }

            lol.push_front(niz[i]);

            if(lol.size()==1)
                pok=i;
            //cout<<"ubaci "<<lol.front()<<endl;

            ///cout<<"front "<<lol.front()<<endl;
        }

        cout<<lol.back()<<" ";
        lol.pop_back();

        ///cout<<"newbek "<<lol.back()<<endl;

        if(pok==gran || kkk==0)
        {
            for(int i=gran+1;i<=n;i++)
            {
                cout<<niz[i]<<" ";
            }
            cout<<endl;
            return 0;
        }

        oldgran = gran+1;
        gran = n-kkk-1;

    }



}