#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, a[N], s[N];
bool check(int x) {
    for(int i = 1; i <= n; i++) s[i] = s[i - 1] + (a[i] >= x ? 1 : -1);
    int mi[2] = {1000000, 1000000};
    for(int i = k; i <= n; i++) {
        int j = i - k;
        mi[j & 1] = min(mi[j & 1], s[j]);
        if(mi[0] <= s[i] - !(i&1)) return true;
        if(mi[1] <= s[i] - (i&1)) return true;
    }
    return false;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    int l = 1, r = n;
    while(l < r) {
        int mid = (l + r + 1) >> 1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l << endl;
    return 0;
}