#include <bits/stdc++.h>
#define ll long long
#define en "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define N 100001
using namespace std;
vector<ll> v;
ll n,k;
bool f(ll x)
{
    vector<ll> tmp(n);
    rep(i,0,n) if(v[i]<x) tmp[i]=-1; else tmp[i]=1;
    vector<ll> pref(n+1,0);
    rep(i,1,n+1) pref[i]=pref[i-1]+tmp[i-1];
    ll mini=0;
    rep(i,k-1,n)
    {
        if(pref[i+1]-mini>0) return true;
        mini=min(mini,pref[i-k+2]);
    }
    return false;
}
void solve()
{
    cin>>n>>k;
    v.resize(n);
    rep(i,0,n) cin>>v[i];
    ll l=1,r=n+1;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        bool b1=f(mid),b2=f(mid+1);
        //cout<<l<<" "<<r<<" "<<b1<<" "<<b2<<endl;
        if(b1 && !b2)
        {
            cout<<mid<<endl;
            return;
        }
        if(b1) l=mid+1;
        else r=mid;
    }
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int t=1;
  //freopen("input.txt", "r", stdin);
  //freopen("ans.txt", "w", stdout);
  //cin>>t;
  for(int i=1;i<=t;i++)
  {
      //cout<<"Case #"<<i<<": ";
      solve();
  }
  return 0;
}
