#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ask(ll l,ll r)
{
    if(l>=r)
        return -1;
    cout<<"? "<<l+1<<" "<<r+1<<endl;
    ll p;
    cin>>p;
    return p-1;
}
void solve()
{
   ll n,k;
   cin>>n>>k;
   ll a[n+1],i;
   for(i=0;i<n;i++)
      cin>>a[i];
   ll low=1,high=n+1;
   while(low+1<high)
   {
       ll b[n+1];
       ll mid=(low+high)/2;
       for(i=0;i<n;i++)
       {
           if(a[i]>=mid)
              b[i]=1;
           else
            b[i]=-1;
       }
       for(i=1;i<n;i++)
       {
           b[i]+=b[i-1];
       }
       ll maxi=b[k-1];
       ll mini=0;
       for(i=k;i<n;i++)
       {
            mini=min(mini,b[i-k]);
            maxi=max(maxi,b[i]-mini);
       }
       if(maxi>0)
           low=mid;
       else
            high=mid;
   }
   cout<<low<<endl;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
}
