#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;

typedef long long ll;

struct segtree_min {
private:
    int n;
    vector<int> node;
 
public:
    segtree_min(vector<int> v) {
        int sz = v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, INT_MAX);
        for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
 
    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2 * x + 1], node[2 * x + 2]);
        }
    }
 
    int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return INT_MAX;
        if (a <= l && r <= b) return node[k];
 
        int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};
struct segtree_max {
private:
    int n;
    vector<int> node;
 
public:
    segtree_max(vector<int> v) {
        int sz = v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, -INT_MAX);
        for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) node[i] = max(node[2 * i + 1], node[2 * i + 2]);
    }
 
    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2 * x + 1], node[2 * x + 2]);
        }
    }
 
    int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return -INT_MAX;
        if (a <= l && r <= b) return node[k];
 
        int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};
vector<int> g[200020];
int used[200020];
void dfs(int x){
    used[x]++;
    for(int i : g[x]){
        if(!used[i])dfs(i);
    }
}
int main(int argc, char const *argv[])
{
    int n,k;scanf("%d %d",&n,&k);
    vector<int> a(n);for(int i = 0;i < n;i++)scanf("%d",&a[i]);
    vector<int> sorted(n,1);
    for(int i = n-2;i >= 0;i--){
        if(a[i] < a[i+1])sorted[i] = sorted[i+1] + 1;else sorted[i] = 1;
    }
    for(int i = 0;i < n;i++)sorted[i] = (sorted[i] >= k);
    segtree_min MIN(a);
    segtree_max MAX(a);
    bool sorted_exist = false;
    for(int i = 0;i < n;i++)if(sorted[i])sorted_exist = true;
    for(int i = 0;i <= n-1-k;i++){
        if(sorted[i])continue;
        if(a[i] == MIN.getmin(i,i+k+1) and a[i+k] == MAX.getmax(i,i+k+1)){
//            cout << MIN.getmin(i,i+k+1) << " " << MAX.getmax(i,i+k+1) << endl;
            g[i].push_back(i+1);
            g[i+1].push_back(i);
        }
    }
    int ans = sorted_exist;
    for(int i = 0;i <= n-k;i++){
        if(sorted[i])continue;
        if(!used[i]){
            ans++;
            dfs(i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17520