#include <bits/stdc++.h>
#define lc (o<<1)
#define rc ((o<<1)|1)
using namespace std;
#define DebugP(x) //cout << "Line" << __LINE__ << " " << #x << "=" << x << endl

typedef long long LL;
typedef complex<double> Comp;

const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int modu = 998244353;

template<class T>
inline void read(T &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9')  {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}

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

bool check(int m) {
	sum[0] = 0;
	int mins = 0;
	for (int i = 1; i <= k; ++i)
		if (a[i] < m) sum[i] = sum[i-1] - 1;
		else sum[i] = sum[i-1] + 1;
	int res = sum[k];
	for (int i = k+1; i <= n; ++i) {
		mins = min(mins, sum[i-k]);
		if (a[i] < m) sum[i] = sum[i-1] - 1;
		else sum[i] = sum[i-1] + 1;
		res = max(res, sum[i]-mins);
	}
	return res > 0;
}

int bs(int l, int r) {
	while (l < r) {
		int mid = (l+r >> 1)+1;
		if (check(mid)) l = mid;
		else r = mid-1;
	}
	return l;
}

int main() {
	// freopen("input.txt", "r", stdin);
	read(n); read(k);
	for (int i = 1; i <= n; ++i) read(a[i]);
	printf("%d\n", bs(1, n));
	return 0;
}