#include <iostream>
#include <bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;a++)
using namespace std;
const int MAX=5*1e5+5,INF=1e9+7;

int n,k,t,a[MAX],minn=INF;
vector<int> res;
multiset<int> s;

int main()
{
    cin>>n>>k;
    For(i,1,n)
    {
        scanf("%i",&a[i]);
    }
    t=n-k;
    For(i,1,k+1)
    s.insert(a[i]);
    For(i,1,n)
    {
       // cout<<i<<endl;
       // cout<<(*s.begin())<<endl;

         if (t-res.size()>=n-i+1)
        {
            res.push_back(a[i]);
            if (i+k+1<=n)
                s.insert(a[i+k+1]);
            //k--;
            //if (i+k+1<=n)
               // s.insert(a[i+k+1]);
        }
        else if ((*s.begin())>=a[i])
        {

            res.push_back(a[i]);
            if (i+k+1<=n)
                s.insert(a[i+k+1]);
        }
        else
        {
            k--;

        }
        s.erase(s.find(a[i]));
       // cout<<i<<" k"<<endl;
    }
    for(int i=0;i<res.size();i++)
        printf("%i ",res[i]);
       // cout<<"GOTOVO";
    return 0;
}

/*
8 3
6 0 3 1 4 2 1 7
*/