# include <iostream>
# include <stdio.h>

using namespace std;

int n, k;
int a[300100];
int sum[300100];
int minsum[300100];

bool ck(int x) {
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1];
    if (a[i] >= x) {
      sum[i]++;
    } else {
      sum[i]--;
    }
    minsum[i] = min(minsum[i - 1], sum[i]);
  }
  for (int i = k; i <= n; i++) {
    if (sum[i] - minsum[i - k] > 0) {
      return 1;
    }
  }
  return 0;
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  int l = 1, r = n;
  while (l < r) {
    if (ck((l + r + 1) / 2)) {
      l = (l + r + 1) / 2;
    } else {
      r = (l + r - 1) / 2;
    }
  }
  printf("%d\n", l);
}
