#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (int)x.size()

const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;

using namespace std;

bool Check (vector <int> a, int m, int k){
        int n = sz(a), sum = 0;
        vector <int> b(n), pref(n);
        for(int i = 0; i<n; i++){
            if(a[i] >= m) b[i] = 1;
            else b[i] = -1;
        }
        pref[0] = min(b[0], 0);
        sum += b[0];
        for(int i = 1; i<n; i++){
            sum += b[i];
            pref[i] = min(pref[i - 1], sum);
            if(i - k >= 0){
                int ss = sum - pref[i - k];
                if(ss > 0) return true;
            }
        }
        if(k == n){
            if(sum > 0) return true;
        }
        return false;
}

void TestCase (){
        int n, k;
        cin >> n >> k;
        vector <int> a(n);
        for(int i = 0; i<n; i++) cin >> a[i];
        int lb = 1, ub = n, ans = 1;
        while(lb <= ub){
            int mid = (lb + ub)/2;
            if(Check(a, mid, k)){
                ans = max(ans, mid);
                lb = mid + 1;
            }
            else ub = mid - 1;
        }
        cout << ans;
}

int main(){
        IOS;
        int T = 1;
        // cin >> T;
        while(T--){
                TestCase();
        }
        return 0;
}
