WA on #1,3,4,5,10
#include<bits/stdc++.h>
#define ll long long
using namespace std;
mt19937 myrand(time(0));
inline ll read(){
ll x=0,w=1;
char ch=0;
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}
void write(ll x){
if(x<0){
putchar('-');
x=-x;
}
static int sta[35];
int top=0;
do{
sta[top++]=x%10,x/=10;
}while(x);
while(top)putchar(sta[--top]+'0');
putchar('\n');
}
deque<ll>q;
int n,m,a[2000005];
main(){
n=read();m=read();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=n;i++){
if(q.empty())write(0);
else write(q.back());
if(q.size()>=m)q.pop_back();
while(a[i]<q.front()&&!q.empty())q.pop_front();
q.push_front(a[i]);
}
return 0;
}