#include <bits/stdc++.h>

using namespace std;

#define ii pair<int,int>
#define fi first
#define se second
#define ld long double
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define eb emplace_back
#define cerr if(0)cerr

const int mxn = 1e5+5;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,k; cin>>n>>k;
	set<int>s;
	vector<int>a(n);
	for(int i=0; i<n; i++){
		cin>>a[i];
		s.insert(a[i]);
	}
	vector<int>pos;
	for(auto x:s)pos.eb(x);
	int lo = 0, hi = sz(pos)-1, ans=0;
	while(lo<=hi){
		int mid = (lo+hi)/2;
		int cur = pos[mid];
		int cnt = 0;
		cerr<<lo<<" "<<hi<<" "<<cur<<"\n";
		vector<int>b(n);
		for(int i=0; i<n; i++){
			if(a[i]>=cur)cnt++;
			else cnt--;
			b[i]=cnt;
			cerr<<b[i]<<" \n"[i==n-1];
		}
		
		int mn = 0, mx = b[k-1];
		cerr<<" "<<b[k-1]<<"\n";
		for(int i=k; i<n; i++){
			mn = min(mn,b[i-k]);
			mx = max(mx,b[i]-mn);
			cerr<<mn<<" "<<mx<<"\n";
		}
		
		if(mx>0){
			ans = mid;
			lo = mid+1;
		}else{
			hi = mid-1;
		}
	}
	cout<<pos[ans]<<"\n";
	return 0;
}
