#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N = 2e5 + 10;

int a[N], b[N], c[N];

signed main() {
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1, b + n + 1);
	int l = 1;
	int ans;
	int r = n;
	while(l <= r) {
		int mid = l + ((r - l) >> 1);
		for(int i = 1; i <= n; ++i) {
			if(a[i] < b[mid]) {
				 c[i] = -1;
			} else c[i] = 1;
			c[i] += c[i - 1];
		}
		int min_pre = 0;
		int mx_sum = c[k];
		// for(int i = 1; i <= n; ++i) {
		// 	cout << c[i] << " ";
		// }
		// cout << endl;
		for(int i = k; i <= n; ++i) {
			mx_sum = max(mx_sum, c[i] - min_pre);
			min_pre = min(c[i - k + 1], min_pre);
		}
		if(mx_sum > 0) {
			// cout << mx_sum<<endl;
			ans = mid;
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}
	cout << b[ans] << endl;

	return 0;
}