#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
int n,k,a[maxn],minn[maxn],sum[maxn],b[maxn];
bool check(int mid){
	for(int i=1;i<=n;i++){
		if(a[i]>=mid)b[i]=1;
		else b[i]=-1;
	}
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+b[i],minn[i]=min(minn[i-1],sum[i]);
	for(int i=k;i<=n;i++){
		if(sum[i]-minn[i-k]>=1)return 1;
	}
	return 0;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	int l=1,r=n,ans=0;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){
			l=mid+1;
			ans=mid;
		}
		else{
			r=mid-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}