#include<cstdio>
#include<iostream>
#include<bitset>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define db double
#define ll long long
#define lb long double
#define be bitset
const int N=1e6+5;
const int INF=1e9+7;
const int M=3005;
const int mod=590027;
inline void rd(ll &x){
	x=0;
	char ch=getchar();bool flag=0;
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')flag=1,ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10ll+ch-'0',ch=getchar();
	if(flag)x=-x;return;
}
inline void rd(int &x){
	x=0;
	char ch=getchar();bool flag=0;
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')flag=1,ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	if(flag)x=-x;return;    
}
inline void rd(db &x){
	scanf("%lf",&x);
}
inline char rch() {
    char c; while ((c = getchar()) != 'N' && c != 'E');
    return c;
}
int n,k,a[N],sum[N],tr[2],b[N];
inline bool check(int x){
	int num=0;tr[0]=tr[1]=0;
	for(int i=1,j=0;i<=n;++i){
		int y=(a[i]>=x)?1:-1;
		sum[i]=sum[i-1]+y;
		if(i>k){
			if((i-k)&1){
				tr[1]=min(tr[1],sum[i-k]);
			}else tr[0]=min(tr[0],sum[i-k]);
		}
		if(i>=k){
			if(i&1){
				if(sum[i]-tr[1]>1)return 1;
				else if(sum[i]-tr[0]>0)return 1;
			}else{
				if(sum[i]-tr[1]>0)return 1;
				else if(sum[i]-tr[0]>1)return 1;
			}
		}
	}return 0;
}
int main(){
	rd(n);rd(k);
	for(int i=1;i<=n;++i){rd(a[i]);b[i]=a[i];}
	sort(b+1,b+1+n);
	int tot=unique(b+1,b+1+n)-b-1;
	int l=1,r=tot,ans=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(b[mid])){
			ans=b[mid];
			l=mid+1;
		}else{
			r=mid-1;
		}
		
	}
	cout<<ans<<endl;
   // system("pause");
    return 0;
}