#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
/* * * *   * * *   	* * * */
/* *
 *
 * Too many mind, no mind.
 *
 * */
bool can(int med, int k, vector <int> &a) {
	int n = a.size();
	vector <int> pre(n), mn(n);
	for (int i = 0; i < n; ++i) pre[i] = a[i] < med ? -1 : 1;
	mn[0] = pre[0];
	for (int i = 1; i < k; ++i) {
		pre[i] += pre[i - 1];
		mn[i] = min(pre[i], mn[i - 1]);
	}
	if (pre[k - 1] > 0) return 1;
	for (int i = k; i < n; ++i) {
		pre[i] += pre[i - 1];
		mn[i] = min(pre[i], mn[i - 1]);
		if (mn[i - k] <= pre[i] - 1 || pre[i] > 0) return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k; cin >> n >> k;
	vector <int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	int lo = 1, hi = n;
	while (lo < hi) {
		int mid = lo + (hi - lo + 1) / 2;
		if (can(mid, k, a)) lo = mid;
		else hi = mid - 1;
	}
	cout << lo << '\n';
	return 0;
}
