#include <bits/stdc++.h>
using namespace std;
const int N=100000+5;
int n,k,cnt,mx=0;
int a[N];
bool check(int x){
int num=0,mn=0,t=0;
for (int i=1;i<=k;i++){
num+=(a[i]>=x)?1:-1;
}
if (num>0)return 1;
for (int i=k+1;i<=n;i++){
num+=(a[i]>=x)?1:-1;
t+=(a[i-k]>=x)?1:-1;
mn=min(mn,t);
if (num-mn>0)return 1;
}
return 0;
}
int main(){
freopen ("player.in","r",stdin);
freopen ("player.out","w",stdout);
scanf("%d%d",&n,&k);
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);mx=max(mx,a[i]);
}
int l=1,r=mx;
while(l<r){
int mid=(l+r+1)/2;
if (check(mid))l=mid;
else r=mid-1;
}
printf("%d\n",l);
return 0;
}