#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;

template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

template <typename T>
struct swag {
    struct node {
        T val, sum;
        node(const T &val, const T &sum) : val(val), sum(sum) {}
    };
    using F = function<T(T, T)>;
    F op;
    stack<node> front_stack, back_stack;
    swag(const F &op) : op(op) {}
    bool empty() const { return front_stack.empty() && back_stack.empty();}
    size_t size() const { return front_stack.size() + back_stack.size();}
    T fold() const {
        assert(!empty());
        if (front_stack.empty()) {
            return back_stack.top().sum;
        } else if (back_stack.empty()) {
            return front_stack.top().sum;
        } else {
            return op(front_stack.top().sum, back_stack.top().sum);
        }
    }
    void push(const T &x) {
        if (back_stack.empty()) {
            back_stack.emplace(x, x);
        } else {
            T s{op(back_stack.top().sum, x)};
            back_stack.emplace(x, s);
        }
    }
    void pop() {
        assert(!empty());
        if (front_stack.empty()) {
            front_stack.emplace(back_stack.top().val, back_stack.top().val);
            back_stack.pop();
            while (!back_stack.empty()) {
                T s{op(back_stack.top().val, front_stack.top().sum)};
                front_stack.emplace(back_stack.top().val, s);
                back_stack.pop();
            }
        }
        front_stack.pop();
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> t(n-k+1);
    {
        int j = 1;
        int cnt = 0;
        rep(i, n-k+1) {
            while (j < i+k) {
                if (a[j-1] > a[j]) cnt++;
                j++;
            }
            t[i] = cnt;
            if (a[i] > a[i+1]) cnt--;
        }
    }

    auto f = [](int a, int b) { return max(a, b); };
    auto g = [](int a, int b) { return min(a, b); };
    swag<int> maxq(f), minq(g);

    vector<bool> same(n-k+1);
    int j = 0;
    rep(i, n-k) {
        while (j < i+k+1) {
            maxq.push(a[j]);
            minq.push(a[j]);
            j++;
        }
        if (maxq.fold() == a[j-1] && minq.fold() == a[i]) same[i+1] = true;
        maxq.pop(); minq.pop();
    }
    int ans = 0;
    rep(i, n-k+1) if (t[i] != 0 && !same[i]) ans++;
    rep(i, n-k+1) if (t[i] == 0) {
        ans++;
        break;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 7376