#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

class MinSegmentTree {
public:
    MinSegmentTree(ll n, ll value) {
        n_ = (ll)pow(2, ceil(log2(n)));
        nodes_.resize(2 * n_ - 1, value);
    }
    void update(ll x, ll v) {
        nodes_[x + n_ - 1] = v;
        for (ll i = (x + n_ - 2) / 2; i > 0; i = (i - 1) / 2) {
            nodes_[i] = min(nodes_[2 * i + 1], nodes_[2 * i + 2]);
        }
        nodes_[0] = min(nodes_[1], nodes_[2]);
    }

    ll getMin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
        if (r < 0) {
            r = n_;
        }
        if (r <= a || b <= l) {
            return INT_MAX;
        }
        if (a <= l && r <= b) {
            return nodes_[k];
        }
        ll lv = getMin(a, b, 2 * k + 1, l, (l + r) / 2);
        ll rv = getMin(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(lv, rv);
    }

private:
    //2のべき乗
    ll n_;
    vector<ll> nodes_;
};

class MaxSegmentTree {
public:
    MaxSegmentTree(ll n, ll value) {
        n_ = (ll)pow(2, ceil(log2(n)));
        nodes_.resize(2 * n_ - 1, value);
    }
    void update(ll x, ll v) {
        nodes_[x + n_ - 1] = v;
        for (ll i = (x + n_ - 2) / 2; i > 0; i = (i - 1) / 2) {
            nodes_[i] = max(nodes_[2 * i + 1], nodes_[2 * i + 2]);
        }
        nodes_[0] = max(nodes_[1], nodes_[2]);
    }

    ll getMax(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
        if (r < 0) {
            r = n_;
        }
        if (r <= a || b <= l) {
            return INT_MIN;
        }
        if (a <= l && r <= b) {
            return nodes_[k];
        }
        ll lv = getMax(a, b, 2 * k + 1, l, (l + r) / 2);
        ll rv = getMax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(lv, rv);
    }

private:
    //2のべき乗
    ll n_;
    vector<ll> nodes_;
};


int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> P(N);
    for (ll i = 0; i < N; i++) {
        cin >> P[i];
    }

    vector<ll> bigger(N, 0);
    bigger[0] = 1;
    for (ll i = 1; i < N; i++) {
        if (P[i - 1] < P[i]) {
            bigger[i] = 1;
        }
    }

    vector<ll> sum_bigger(N + 1, 0);
    for (ll i = 0; i < N; i++) {
        sum_bigger[i + 1] = sum_bigger[i] + bigger[i];
    }

    //ソートしても変わらないものを数える
    ll same_num = 0;
    vector<bool> same(N, false);
    for (ll i = 0; i <= N - K; i++) {
        ll diff = sum_bigger[i + K] - sum_bigger[i] - bigger[i];
        if (diff >= K - 1) {
            same_num++;
            same[i] = true;
        }
    }

    MinSegmentTree min_st(N, 0);
    MaxSegmentTree max_st(N, 0);
    for (ll i = 0; i < N; i++) {
        min_st.update(i, P[i]);
        max_st.update(i, P[i]);
    }

    ll ans = N - K + 1 - max(same_num - 1, (ll)0);
    for (ll i = 0; i < N - K; i++) {
        if (same[i]) {
            //同じになるとして数えたものは飛ばす
            continue;
        }
        //[i, i + K)内での最小値がP[i]で
        //[i + 1, i + 1 +K)内での最大値がP[i + K]のとき
        //[i, i + K)をソートした結果と[i + 1, i + 1 + K)をソートした結果は一致する
        ll min_value = min_st.getMin(i, i + K);
        ll max_value = max_st.getMax(i + 1, i + 1 + K);
        if (min_value == P[i] && max_value == P[i + K]) {
            ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 13184