#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int maxr = 1e5+10;
typedef long long ll;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int n,k;
int a[maxn],s[maxn],minv[maxn];
bool check(int mid)
{
	memset(minv,0x3f,sizeof(minv));
	minv[0] = 0;
	for(int i=1;i<=n;i++)	s[i] = s[i - 1] + (a[i] >= mid ? 1 : -1);
	for(int i=1;i<=n;i++)	minv[i] = min(minv[i - 1],s[i]);
	for(int i=k;i<=n;i++)	if(s[i] - minv[i - k] > 0)	return true;
	return false;
}
int main()
{
	int T;
	T = 1;
	while(T--)
	{
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		int l=1,r=2e5+1,mid;
		while(l<r)
		{
			mid = (l+r+1)>>1;
			if(check(mid)) l=mid;
			else r=mid-1;
		}
		printf("%d",l);
	}
	return 0;
}
