#include<bits/stdc++.h>
using namespace std ;
#define int long long
int possible(int x, int *a, int n, int k){
    int pref[n], mini[n], i, ans;

    pref[0] = (a[0] >= x) - (a[0] < x);
    mini[0] = min(0ll, pref[0]);

    for(i = 1; i < n; i++){
        pref[i] = pref[i - 1] + (a[i] >= x) - (a[i] < x);
        mini[i] = min(mini[i-1], pref[i]);
    }    

    ans = pref[k - 1];
    
    for(i = k; i < n; i++)
        if(i - k >= 0)
            ans = max(ans, pref[i] - mini[i - k]);
     
    return (ans > 0);
    
}
signed main (){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    int n, k, i;
    cin >> n >> k;
    int a[n];
    for(i = 0; i < n; i++)
        cin >> a[i];

    int l = 1, r = n;
    while(l < r){
        int m = (l + r + 1) / 2;
        if(possible(m, a, n, k))
            l = m;
        else 
            r = m - 1;    
    }   
    cout << l << endl; 
    return 0 ;
}