#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
//order_set x;
#define fir first
#define sec second
#define pb push_back
#define ll long long
#define sz size
#define mp make_pair
#define en "\n"
#define victor vector
#define ld long double
//#define int128 __int128
vector<ll> a(300000);
ll n, k;
bool check(ll x)
{
    ll pref[n], suf[n+1], near[n];
    for (int i = 0; i < n; i++)
    {
        pref[i] = -1;
        if (a[i] >= x)
            pref[i] = 1;
        suf[i] = pref[i];
    }
    for (int i = 0; i < n; i++)
        if (a[i] >= x)
            near[i] = i;
        else
            near[i] = -1;
    for (int i = n-2; i >= 0; i--)
        if (near[i] == -1)
            near[i] = near[i+1];
    for (int i = 1; i < n; i++)
        pref[i] += pref[i-1];
    suf[n] = 0;
    for (int i = n-2; i >= 0; i--)
        suf[i] += suf[i+1];
    for (int i = n-1; i >= 0; i--)
        suf[i] = min(suf[i], suf[i+1]);
    bool ok = false;
    for (int i = 0; i < n; i++)
        if (near[i] != -1)
        {
            if (i+k > n)
                break;
            ll w = pref[n-1];
            if (i > 0)
                w -= pref[i-1];
            w -= suf[max(i+k-1ll, near[i])+1];
            if (w > 0)
                return true;
        }
    return false;

}
int main()
{
    //freopen("input1.txt", "r", stdin);
    //freopen("output1.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<ll> b(n);
    for (int i = 0; i < n; i++)
        b[i] = a[i];
    sort(b.begin(), b.end());
    ll l = 0, r = n-1;
    while (l < r)
    {
        ll mid = (l+r) / 2;
        mid++;
        if (check(b[mid]))
            l = mid;
        else
            r = mid-1;
    }
    cout << b[l] << en;
}

