#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
bool checkfunc(vlli &a, lli n, lli k, lli mid)
{
	//we should have net diff>=1, then only we will take it as answer
	set<lli> diffs;//will only store diffs if its distance from current >=k 
	vlli dcount(n);
	if(a[0]>=mid)dcount[0]=1;
	else dcount[0]=-1;
	flli(i,1,k-1)
	{
		dcount[i]=dcount[i-1];
		if(a[i]>=mid)dcount[i]++;
		else dcount[i]--;
	}
	if(dcount[k-1]>=1)return true;
	flli(i,k,n-1)
	{
		diffs.insert(dcount[i-k]);
		dcount[i]=dcount[i-1];
		if(a[i]>=mid)dcount[i]++;
		else dcount[i]--;
		if(dcount[i]>=1)return true;
		lli tar=dcount[i]-1;
		auto firsti=diffs.begin();
		if(*firsti>tar)
			continue;
		auto lasti=diffs.rbegin();
		if(*lasti<=tar)return true;
		auto findi=diffs.lower_bound(tar);
		if(*findi==tar || findi!=diffs.begin())return true;
	}
	return false;
}
lli findans(vlli &a, lli n,lli k)
{
	lli l=1,r=n;
	while(l<=r)
	{
		if(l==r)return l;
		lli mid=(l+r)/2;
		bool flag1=checkfunc(a,n,k,mid);
		if(flag1)
		{
			if(mid==r)return mid;
			else 
			{
				bool flag2=checkfunc(a,n,k,mid+1);
				if(flag2)l=mid+1;
				else return mid;
			}
		}
		else r=mid-1;
	}
	return l;
}
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    lli n,k;cin>>n>>k;
    vlli a(n);flli(i,0,n-1)cin>>a[i];
    lli ans=findans(a,n,k);
    cout<<ans<<endl;
    //bool var=checkfunc(a,n,k,4);cout<<var<<endl;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}