#include <bits/stdc++.h>
using namespace std; 
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
#define TIME cerr<<"Time Taken:"<<(float)clock()/CLOCKS_PER_SEC*1000<<"ms"<<endl
//  When something is important enough, you do it even if the odds are not in your favor.
LL check(LL n,LL k,LL mid,LL arr[]){
  LL i,j;
  LL a[n];
  fo(i,0,n){
    if(mid<=arr[i]) a[i]=1;
    else a[i]=-1;
  }
  LL sum[n];sum[0]=a[0];
  fo(i,1,n) sum[i]=a[i]+sum[i-1];

  LL mn=0,f=0;
  if(sum[k-1]>0) f=1;
  fo(i,k,n){
    mn=min(mn,sum[i-k]);
    if(sum[i]-mn>0) f=1;
  }

  return f;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef somujena
    freopen("/home/somujena/competitive/input.txt", "r", stdin);
    freopen("/home/somujena/competitive/output.txt", "w", stdout);
    #endif
    // code goes here
    LL t=1;//cin>>t;
    while(t--){
      LL n,k,i,j;cin>>n>>k;
      LL a[n];
      fo(i,0,n) cin>>a[i];
      LL ans,l=1,r=1e6;
      while(l<=r){
        LL mid=(l+r)/2;
        if(check(n,k,mid,a)){ 
          ans=mid;
          l=mid+1;
        }
        else{
          r=mid-1;
        }
      }
      cout<<ans;
    }
    TIME;
    return 0;
}