//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        rep(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr <<  #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }
#define kyra   1000000007
#define N 300003
const long long INF=1e18;
vector<int> v[26];
int n,k;
int a[N];
int temp[N];


bool good(int m)
 {
   rep(i,0,n)
     {
      if(a[i]>=m)
          {
            temp[i]=1;

          }
          else
            temp[i]=-1;

          if(i!=0)
             temp[i]+=temp[i-1];
     }
     // for(int i=0;i<n;i++)
     //    cout<<temp[i]<<" ";
     int mi=INF;
     rep(i,k-1,n)
      {
         mi=min(mi, temp[i-k]);
         if(temp[i]-mi>0)
           {
            return true;
           }

         
      }
      return false;

 }

void solve()
{ 
   
   cin>>n>>k;
   rep(i,0,n)
     cin>>a[i];

    int l=-1;
    int r=N;

    while(r>l+1)
       {
        int m=(l+r)/2;
        if(good(m))
           {
            l=m;
           }
           else
             r=m;
       }
cout<<l<<endl;
    

}

signed main()
{fast
  
   #ifdef NCR
        init();
   #endif
  
   int t=1;
  // cin>>t;
   
   while(t--)
     {
      solve();
     }
}
