#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
#define MAXN 500010
int a[MAXN];
priority_queue<pii, vector<pii>, greater<pii> > pq;
vector<int> rez;
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
    int N, K; cin >> N >> K;
    for(int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    int l = 1;
    for(int i = 1; i <= K+1; i++) {
        pq.push({a[i], i});
    }
    int idx = K+2;
    while(!pq.empty() && l <= N) {
        pii x = pq.top(); pq.pop();
        if(x.se >= l) {
            rez.pb(x.fi);
            K -= x.se-l;
            l = x.se+1;
            //PRINT(l);
            //PRINT(idx);
            //PRINT(x.fi);
            //PRINT(x.se);
            //PRINT(K);
            while(idx-l+1 <= K+1) {
                //PRINT(1111);
                pq.push({a[idx], idx});
                idx++;
            }
        }
    }
    for(auto x : rez) cout << x << ' ';
    return 0;
}