#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[10005];
signed main(){
scanf("%d%d",&n,&k);
for(int i = 1;i <= n;i ++)scanf("%d",&a[i]);
// vector<int> stk;
// for(int i = 1;i <= k&&i<=n;i ++)stk.push_back(a[i]);
// sort(stk.begin(),stk.end());
// int ptr = k+1;
// for(int i = 1;i <= n;i ++){
// while(ptr<=n&&stk.size()<k)stk.insert(lower_bound(stk.begin(),stk.end(),a[ptr]),a[ptr]),ptr++;
// printf("%d ",stk[0]);
// stk.erase(stk.begin());
// }
multiset<int> s;
for(int i = 1;i <= k;i ++)
s.insert(a[i]);
int ptr = k+1;
int cnt = n;
while(cnt --){
while(s.size()<k&&ptr<=n){
s.insert(a[ptr++]);
}
cout << (*s.begin()) << " ";
s.erase(s.begin());
}
return 0;
}
/*
5 2
6 5 2 9 15
*/