#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
#define pf printf
#define pq priority_queue
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define rep(i, s, e) for(int i = s;i <= e; ++ i)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
const int N = 200010;

int n, k, cnt, a[N], sum[N];
bool check(int x)
{
//	memset(sum, 0, sizeof(sum));
	for(int i = 1;i <= n; ++ i) {
		if(a[i] >= x) sum[i] = sum[i-1] + 1;
		else sum[i] = sum[i-1] - 1;
	}
	int minx = 1e9, maxn = -1;
	for(int i = k;i <= n; ++ i) {
		int s = sum[i] - sum[i-k];
		minx = min(minx, sum[i-k]);
		maxn = max(maxn, sum[i] - minx);
	}
	if(maxn > 0) return 1;
	return 0;
}
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n; ++ i) {
		scanf("%d", &a[i]);
	}
	int l = 1, r = n;
	int res;
	while(l <= r) {	
		int mid = l + r >> 1;
		if(check(mid)) res = mid, l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", res);
}

