/*
 #include <ext/pb_ds/assoc_container.hpp>
 #include <ext/pb_ds/priority_queue.hpp>

 using namespace __gnu_pbds;


__gnu_pbds::priority_queue<int, less<int>> pq;
gp_hash_table<int, int> mp;
*/

/** Begin fast allocation */
/*
const int mx_MEM = 10 * 1e7;
int mpos = 0;
char mem[mx_MEM];

inline void *operator new(size_t n) {
    assert((mpos += n) <= mx_MEM);
    return (void *) (mem + mpos - n);
}

inline void operator delete(void *) noexcept {} // must have!
*/
/** End fast allocation */

/** Pragmas */
// mt19937 gen(2281337);

//#pragma GCC optimize("O3", "Ofast", "unroll-loops", "unswitch-loops", "fast-math", "no-stack-protector")

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx")
// sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,
//#pragma comment(linker, "/STACK:66777216")

/*
 * @author kamil.sharipov
 */

#include <bits/stdc++.h>

// #define int long long
#define all(x) (x).begin(), (x).end()
#define fo(i, a, b) for (int i = a; i < b; ++i)
#define ll long long
#define pii pair<int, int>

using namespace std;

int n, k;
vector<int> a, ms, pref;

bool ch(int x) {
    for (int i = 0; i < n; ++i) {
        if (a[i] >= x) ms[i] = 1;
        else ms[i] = -1;
    }
    pref[0] = ms[0];
    for (int i = 1; i < n; ++i) {
        pref[i] = pref[i - 1] + ms[i];
    }

    int mn = 0;

    for (int i = k - 1; i < n; ++i) {
        if (pref[i] > mn) return true;
        mn = min(mn, pref[i - k + 1]);
    }

    return false;
}

signed main() {
#ifdef _LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin >> n >> k;
    a.resize(n), ms.resize(n), pref.resize(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int l = 0;
    int r = n + 1;
    while (l + 1 < r) {
        int mid = (l + r) / 2;
        if (ch(mid)) l = mid;
        else r = mid;
    }
    cout << l;
}




