#include<bits/stdc++.h>
using namespace std;
 
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
#define sf scanf
#define pf printf
#define nl printf("\n")
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d%d",&x,&y)
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define chk cerr<<"CAME HERE"<<endl
#define dbug(x) cerr<<"value of "<<#x<<" = "<<x<<endl
mt19937_64 rng((uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
inline ll rand(ll l, ll r){uniform_int_distribution<ll> RNG(l,r);return RNG(rng);}
template<typename T>inline void togglebit(T &x, int pos){x^=(T(1)<<pos);}
template<typename T>inline bool chkbit(T x, int pos){return bool(x&(T(1)<<pos));}
template<typename T>inline void setbit(T &x, int pos){x|=(T(1)<<pos);}
template<typename T>inline void resetbit(T &x, int pos){if(chkbit(x,pos))togglebit(x,pos);}
 
 
const int N = 1e5+5;
 
 
void work(vector<int>& arr, int k) {
        vector<int>ans;
        multiset<int>R,L;
        
        auto balance = [&](){     
            if(L.size() > R.size()+1){
                R.insert(*L.rbegin());
                L.erase(L.find(*L.rbegin()));
            }
            if(R.size() > L.size()){
                L.insert(*R.begin());
                R.erase(R.begin());
            }
        };
        
		auto Del = [&](int x){
			if(L.count(x))L.erase(L.find(x));
            else R.erase(R.find(x));
            balance();
		};
		
        for(int i=0,n=sz(arr),x; i<n; i++){
			x=arr[i];
            if(L.empty())L.insert(x);
			else if(*L.rbegin()>x)L.insert(x);
			else R.insert(x);
			balance();
           
            
            if(sz(L)+sz(R)==k){
				pf("%d ",*L.rbegin());
 
				x=arr[i-k+1];
				Del(x);
				// if(L.count(x))L.erase(L.find(x));
				// else R.erase(R.find(x));
				// balance();
            }
        }
		
 
 
    }
 
void solve(int casenum){
	int n,k;
	sii(n,k);
	vi arr(n);
	FOR(i,n)si(arr[i]);
	work(arr,k);
 
}
 
int main(){
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int T=1;
    //scanf("%d",&T);
    //cin>>T;
    for(int i=1; i<=T; i++)
        solve(i);
 
return 0;
}