#include<bits/stdc++.h>
using namespace std;
int n,m;
const int maxn = 2e6 + 10;
int a[maxn];
int res[maxn];
deque<int>q;
int main(){
freopen("求m区间内的最小值.in","r",stdin);
freopen("求m区间内的最值.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i ++)
cin >> a[i];
for(int i = 1;i <= n;i ++){
while(!q.empty() && a[i] < a[q.back()])
q.pop_back();
q.push_back(i);
if(i >= m){
while(!q.empty() && q.front() <= i - m)
q.pop_front();
}
res[i] = a[q.front()];
}
cout << 0 << "\n";
for(int i = 1;i < n;i ++){
cout << res[i];
cout << endl;
}
return 0;
}
80TLE