#include<bits/stdc++.h>
using namespace std;
long long n,a[500100],k,i,j,x,y,z,broj,tren;
vector<long long>odg;
vector< pair<long long,long long> > vuk;
main()
{
    ios_base::sync_with_stdio(0);
cin>>n>>k;
for(i=0;i<n;i++)
{
cin>>a[i];
vuk.push_back(make_pair(a[i],i));
}

sort(vuk.begin(),vuk.end());

for(i=0;i<n;i++)
if(vuk[i].second-odg.size()<=k && vuk[i].second>=tren)
{
odg.push_back(vuk[i].first);
tren=vuk[i].second;
}

for(i=0;i<odg.size();i++)
cout<<odg[i]<<" ";
for(i=tren+1;i<n;i++)
    cout<<a[i]<<" ";
return 0;
}