#include <bits/stdc++.h>

using namespace std;

#define inf          1e15
#define mod          1000000007
#define N            100001
#define ll           long long int
#define vint         vector<int>
#define vll          vector<ll>
#define vstr         vector<string>
#define vvint        vector<vector<int> >
#define vvll         vector<vector<ll> >
#define vint_pair    vector<pair<int,int> >
#define input(arr)   for(auto &x:arr) cin>>x;
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()

int main() {
    int t=1;
    //cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vint arr(n);
        input(arr);
        int l = 1, r = n;
        int mid;
        vint pre(n+1);
        int ans=1;
        int mn;
        bool flag;
        while(l<=r){
            mn = INT_MAX;
            mid = l + (r-l)/2;
            pre[0] = 0;
            flag = false;
            for(int i=1;i<=n;++i){
                pre[i] = (arr[i-1]>=mid) ? 1 : -1;
                pre[i] += pre[i-1];
                //mn = min(mn, pre[i-1]);
                if(i>=k){
                    mn = min(mn, pre[i-k]);
                    if(pre[i]-mn>0){
                        ans = mid;
                        flag = true;
                    }
                }
            }
            if(flag)
                l = mid+1;
            else
                r = mid-1;
        }
        cout<<ans<<endl;
    }
}
