#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define INF 0x3f3f3f3f
#define f first
#define s second
#define FOR(i, n) for(int i = 1; i <= n; i ++)
#define FFOR(i, a, b) for(int i = a; i <= b; i ++)
#define pii pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mem(x, a) memset(x, a, sizeof(x))
#define loli ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int maxn = 1e6 + 50;

int n, k, a[maxn], sum[maxn];

bool solve(int x) {
	int cnt = 0, mn = INF;
	FOR(i, n) {
		if(a[i] >= x) cnt ++;
		else cnt --;
		sum[i] = cnt;
		if(i >= k) {
			mn = min(sum[i - k], mn);
			if(cnt - mn > 0) return 1;
		}
	}
	return 0;
}

signed main(){
	loli;
	cin >> n >> k;
	FOR(i, n) cin >> a[i];
	int l = 1, r = n, ans = 0;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(solve(mid)) {
			ans = max(ans, mid);
			l = mid + 1;
		}
		else r = mid - 1;
	}
	cout << ans << "\n";
}

