#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define atn 222222
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define f(i,a,b) for(int i = a;i <= b;++i)
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar_unlocked();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar_unlocked();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar_unlocked();}
return x*f;
}
inline void out(int x){
if(x<0)putchar_unlocked('-'),x=-x;
if(x>9)out(x/10);
putchar_unlocked((x%10)|0x30);
}
int a[2222222];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,m;
n=read(),m=read();
multiset<int> s;
f(i,1,n)a[i]=read();
out(0);
f(i,1,n-1){
s.insert(a[i]);
if(i>m){
s.erase(s.find(a[i-m]));
}
out(*s.begin());
putchar('\n');
}
return 0;
//十年OI一场空,define int 见祖宗。
//十年OI一场空,不开long long见祖宗。
}
时间复杂度应该是 O(nlogm) 的