#include<bits/stdc++.h>
using namespace std;
long long c[10001],minn=2*0x3f3f3f3f,w=-1;
long long m(long long s,long long b,long long a)
{
w=-1;
if(s>a)s=a;
minn=2*0x3f3f3f3f;
for(int i=b;i<=s;i++)
{
if(minn>c[i])
{
minn=c[i];
w=i;
}
}
return w;
}
stack<long long>s;
int main()
{
long long a,b=0,n,x;
cin>>a>>n;
for(int i=0;i<a;i++)
{
cin>>c[i];
}
a--;
while(b<=a)
{
x=m(b+n-s.size()-1,b,a);
if(s.empty())
{
for(int i=b;i<=x;i++)
{
s.push(c[i]);
}
cout<<s.top()<<" ";
s.pop();
b=x+1;
}
else if(c[x]<=s.top())
{
for(int i=b;i<=x;i++)
{
s.push(c[i]);
}
cout<<s.top()<<" ";
s.pop();
b=x+1;
}
else
{
cout<<s.top()<<" ";
s.pop();
}
}
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
return 0;
}
救命!!!