#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define srt(x) sort(all(x))
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
#define msv(x, v) memset((x), (v), sizeof(x))
#define ms(x) memset(x, 0, sizeof(x))
#define dbg(x) cerr << #x " = " << (x) << endl

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;

struct Scanner {

    bool hasNext = 1;
    bool hasRead = 1;

    int nextInt() {
        hasRead = 0;
        int res = 0;
        char flag = 1, ch = getchar();
        while(ch != EOF && !isdigit(ch)) {
            hasRead = 1;
            flag = (ch == '-') ? -flag : flag;
            ch = getchar();
        }
        while(ch != EOF && isdigit(ch)) {
            hasRead = 1;
            res = res * 10 + (ch - '0');
            ch = getchar();
        }
        if(ch == EOF)
            hasNext = 0;
        return res * flag;
    }

    ll nextLL() {
        hasRead = 0;
        ll res = 0;
        char flag = 1, ch = getchar();
        while(ch != EOF && !isdigit(ch)) {
            hasRead = 1;
            flag = (ch == '-') ? -flag : flag;
            ch = getchar();
        }
        while(ch != EOF && isdigit(ch)) {
            hasRead = 1;
            res = res * 10 + (ch - '0');
            ch = getchar();
        }
        if(ch == EOF)
            hasNext = 0;
        return res * flag;
    }

    char nextChar() {
        hasRead = 0;
        char ch = getchar();
        while(ch != EOF && isspace(ch)) {
            hasRead = 1;
            ch = getchar();
        }
        if(ch == EOF)
            hasNext = 0;
        return ch;
    }

    int nextString(char *str) {
        hasRead = 0;
        int len = 0;
        char ch = getchar();
        while(ch != EOF && isspace(ch)) {
            hasRead = 1;
            ch = getchar();
        }
        while(ch != EOF && !isspace(ch)) {
            hasRead = 1;
            str[++len] = ch;
            ch = getchar();
        }
        str[len + 1] = 0;
        if(ch == EOF)
            hasNext = 0;
        return len;
    }

} sc;

ll rd() {
    ll x = sc.nextLL();
    return x;
}

void rd(int &x) {
    x = sc.nextInt();
}

void rd(ll &x) {
    x = sc.nextLL();
}

void rd(char &x) {
    x = sc.nextChar();
}

void rd(char* x) {
    sc.nextString(x);
}

template<typename T1, typename T2>
void rd(pair<T1, T2> &x) {
    rd(x.first);
    rd(x.second);
}

template<typename T>
void rd(T *x, int n) {
    for(int i = 1; i <= n; ++i)
        rd(x[i]);
}

void printInt(int x) {
    if(x < 0) {
        putchar('-');
        x = -x;
    }
    if(x >= 10)
        printInt(x / 10);
    putchar('0' + x % 10);
}

void printLL(ll x) {
    if(x < 0) {
        putchar('-');
        x = -x;
    }
    if(x >= 10)
        printLL(x / 10);
    putchar('0' + x % 10);
}

void pr(int x, char ch = '\n') {
    printInt(x);
    putchar(ch);
}

void pr(ll x, char ch = '\n') {
    printLL(x);
    putchar(ch);
}

template<typename T1, typename T2>
void pr(pair<T1, T2> x, char ch = '\n') {
#ifdef LOCAL
    putchar('<');
    pr(x.first, ' ');
    pr(x.second, '>');
    putchar(ch);
    return;
#endif // LOCAL
    pr(x.first, ' ');
    pr(x.second, ch);
}

template<typename T>
void pr(T *x, int n) {
    for(int i = 1; i <= n; ++i)
        pr(x[i], " \n"[i == n]);
}

template<typename T>
void pr(vector<T> &x) {
    int n = x.size();
    for(int i = 1; i <= n; ++i)
        pr(x[i - 1], " \n"[i == n]);
}

template<typename T>
void cmin(T &x, T y) {
    if(y < x)
        x = y;
}

template<typename T>
void cmax(T &x, T y) {
    if(y > x)
        x = y;
}

/* begin */

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1000000007;
//const int MOD = 998244353;

const int MAXN = 2e5 + 10;

int M;
int c[MAXN];
int b[MAXN];
int pre[MAXN];

struct SegmentTree {

#define ls (u << 1)
#define rs (u << 1 | 1)
#define mid ((l + r) >> 1)

    static const int MAXN = 2e5 + 10;
    static const int INF = 1e9 + 10;

    int mx[MAXN << 2];
    int sum[MAXN << 2];

    void PushUp(int u) {
        mx[u] = max(mx[ls], sum[ls] + mx[rs]);
        sum[u] = sum[ls] + sum[rs];
    }

    void Build(int u, int l, int r) {
        if(l == r) {
            mx[u] = sum[u] = b[l];
            return;
        }
        Build(ls, l, mid);
        Build(rs, mid + 1, r);
        PushUp(u);
    }

    int QueryMax(int u, int l, int r, int L, int R) {
        if(L <= l && r <= R)
            return mx[u];
        int res = -INF;
        if(L <= mid) res = max(res, QueryMax(ls, l, mid, L, R));
        if(R >= mid + 1) {
            int tmp = 0;
            if(L <= mid)
                tmp = QuerySum(ls, l, mid, L, R);
            tmp += QueryMax(rs, mid + 1, r, L, R);
            res = max(res, tmp);
        }
        return res;
    }

    int QuerySum(int u, int l, int r, int L, int R) {
        L = max(l, L);
        R = min(r, R);
        if(L > R)
            return 0;
        return pre[R] - pre[L - 1];
    }

#undef ls
#undef rs
#undef mid

} st;

int n, k;
int a[MAXN];

bool check(int x) {
    for(int i = 1; i <= n; ++i) {
        if(a[i] >= x)
            b[i] = 1;
        else
            b[i] = -1;
        pre[i] = pre[i - 1] + b[i];
    }
    st.Build(1, 1, n);
    for(int i = 1; i <= n; ++i) {
        if(i + k - 1 > n)
            break;
        int tmpsum = st.QuerySum(1, 1, n, i, i + k - 1);
        if(tmpsum > 0)
            return true;
        if(i + k <= n) {
            tmpsum += st.QueryMax(1, 1, n, i + k, n);
            if(tmpsum > 0)
                return true;
        }
    }
    return false;
}

struct Solver {

    void InitOnce() {
    }

    void Read() {
        rd(n);
        rd(k);
        rd(a, n);
    }

    void Solve() {
        M = n;
        for(int i = 1; i <= M; ++i)
            c[i] = a[i];
        sort(c + 1, c + 1 + M);
        M = unique(c + 1, c + 1 + M) - (c + 1);
        int L = 1, R = M;
        while(1) {
            int MID = (L + R) >> 1;
            if(L == MID) {
                if(check(c[R]))
                    L = R;
                else
                    R = L;
                break;
            }
            if(check(c[MID]))
                L = MID;
            else
                R = MID - 1;
        }
        pr(c[L]);
    }

} solver;

/* end */

int main() {
#ifdef LOCAL
    freopen("A.in", "r", stdin);
#endif // LOCAL
    solver.InitOnce();
    int t = INF;
//    t = sc.nextInt();
    while(t--) {
        solver.Read();
        if(!sc.hasRead)
            break;
        solver.Solve();
        if(!sc.hasNext)
            break;
    }
    return 0;
}
