#include<bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e5 + 5;
int n, k, s[N], a[N];
bool Check(int m)
{
    for (int i = 1; i <= n; i++) {
        s[i] = s[i - 1] + (a[i] >= m ? 1 : -1);
    }
    int mn = 0;
    int mx = s[k];
    for (int i = k; i <= n; i++) {
        // 起点从最小的开始
        mn = min(mn, s[i - k]);
        // 重点到i点为止，如果>=m的个数超过了<m的个数 就ok
        mx = max(mx, s[i] - mn);
        if (mx > 0) {
            return true;
        }
    }
    return false;
}
int main()
{
    cin >> n >> k;
    for (int i = 1; i <=n ; i++) {
        cin >> a[i];
    }
    int l = 1;
    int r = n + 1;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (Check(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << l << endl;
    return 0;
}