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

int main() {
    int n, k; cin >> n >> k;
    vector<int> p(n);
    for(auto& x : p) cin >> x;

    vector<int> dp(n);
    for(int i = 1; i < n; ++i) {
        if(p[i - 1] < p[i]) {
            dp[i] = dp[i - 1] + 1;
        }
    }

    set<int> s;
    int ans = 0, sorted = 0;
    if(dp[k - 1] == k - 1) {
        sorted = 1;
    } else {
        ans = 1;
    }
    for(int i = 0; i < k; ++i) {
        s.insert(p[i]);
    }
    for(int i = k; i < n; ++i) {
        bool add = *s.begin() != p[i - k];
        s.insert(p[i]);
        s.erase(p[i - k]);
        add |= *prev(s.end()) != p[i];
        if(add) {
            if(dp[i] >= k - 1) {
                sorted = 1;
            } else {
                ans += 1;
            }
        }
    }
    ans += sorted;

    cout << ans << endl;
}
