#include<bits/stdc++.h>
using namespace std;
#define for1(i,m,n) for(int i=m;i<=n;i++)
#define for0(i,m,n) for(int i=m;i<n;i++)
//#define int int
#define el '\n'
#define fi first
#define se second
#define ii pair<int,int>
#define vll(i) i.begin(),i.end()
const int N=1e7;
const int mod=1e9+7;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;cin>>n>>k;
multiset<int,greater<int>>s;
auto it=s.end();
while(n--){
int x;cin>>x;
s.emplace(x);
if(s.size()<k) continue;
if(s.size()==k) {
it=s.end();
--it;
cout<<*it<<el;
continue;
}
if(x>=*it) --it;
cout<<*it<<el;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgZm9yMShpLG0sbikgZm9yKGludCBpPW07aTw9bjtpKyspCiNkZWZpbmUgZm9yMChpLG0sbikgZm9yKGludCBpPW07aTxuO2krKykKCi8vI2RlZmluZSBpbnQgIGludAojZGVmaW5lIGVsICdcbicKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIGlpIHBhaXI8aW50LGludD4KI2RlZmluZSB2bGwoaSkgaS5iZWdpbigpLGkuZW5kKCkKCmNvbnN0IGludCBOPTFlNzsKY29uc3QgaW50IG1vZD0xZTkrNzsKCgoKc2lnbmVkIG1haW4oKXsKICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogIGNpbi50aWUoMCk7CiAgY291dC50aWUoMCk7CiAKaW50IG4saztjaW4+Pm4+Pms7CgptdWx0aXNldDxpbnQsZ3JlYXRlcjxpbnQ+PnM7CmF1dG8gaXQ9cy5lbmQoKTsKd2hpbGUobi0tKXsKCiAgaW50IHg7Y2luPj54OwogIHMuZW1wbGFjZSh4KTsKICAKICBpZihzLnNpemUoKTxrKSBjb250aW51ZTsKICBpZihzLnNpemUoKT09aykgewogICAgaXQ9cy5lbmQoKTsKICAgIC0taXQ7CiAgICBjb3V0PDwqaXQ8PGVsOwogICAgY29udGludWU7CiAgfQogIAogIGlmKHg+PSppdCkgLS1pdDsKICBjb3V0PDwqaXQ8PGVsOwp9CiAgICByZXR1cm4gMDsKfQo=