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

int N, K;
int P[200010];
int down[200010], dacc[200010];
vector<int> sorted;
set<int> root;
 
bool is_sort(int i, int j) {
    return dacc[j+1]-dacc[i+1]==0;
}

struct segtreeM {
    int size;
    vector<int> node;
    
    segtreeM(int n) {
        size = 1;
        while (size<n) size *= 2;
        node.resize(2*size-1);
        fill(node.begin(), node.end(), -1000000000);
    }
    
    void update(int k, int a) {
        k += size-1;
        node[k] = a;
        while (k>0) {
            k = (k-1)/2;
            node[k] = max(node[2*k+1], node[2*k+2]);
        }
    }
    
    int query(int a, int b, int k, int l, int r) {
        if (r<=a || b<=l) return -1000000000;
        if (a<=l && r<=b) return node[k];
        else {
            int vl = query(a, b, 2*k+1, l, (l+r)/2);
            int vr = query(a, b, 2*k+2, (l+r)/2, r);
            return max(vl, vr);
        }
    }
    
    int get(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};

struct segtreem {
    int size;
    vector<int> node;
    
    segtreem(int n) {
        size = 1;
        while (size<n) size *= 2;
        node.resize(2*size-1);
        fill(node.begin(), node.end(), 1000000000);
    }
    
    void update(int k, int a) {
        k += size-1;
        node[k] = a;
        while (k>0) {
            k = (k-1)/2;
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }
    
    int query(int a, int b, int k, int l, int r) {
        if (r<=a || b<=l) return 1000000000;
        if (a<=l && r<=b) return node[k];
        else {
            int vl = query(a, b, 2*k+1, l, (l+r)/2);
            int vr = query(a, b, 2*k+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
    
    int get(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};

struct Unionfind {
    vector<int> par, rank;
    
    Unionfind(int n) {
        par.resize(n);
        fill(par.begin(), par.end(), -1);
        rank.resize(n);
    }
    
    int root(int x) {
        int r = x;
        while (!(par[r]<0)) r = par[r];
        int t = x;
        
        while (t!=r) {
            int tmp = t;
            t = par[t];
            par[tmp] = r;
        }
        
        return r;
    }
    
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        
        if (rx==ry) return;
        
        if (rank[rx]<=rank[ry]) {
            par[ry] += par[rx];
            par[rx] = ry;
            
            if (rank[rx]==rank[ry]) rank[ry]++;
        }
        else {
            par[rx] += par[ry];
            par[ry] = rx;
        }
    }
    
    bool is_same(int x, int y) {
        return root(x)==root(y);
    }
    
    int count(int x) {
        return -par[root(x)];
    }
};

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    rep(i, N) cin >> P[i];
    for (int i=1; i<N; i++) if (P[i-1]>P[i]) down[i] = 1;
    rep(i, N) dacc[i+1] = dacc[i]+down[i];
    
    segtreeM stM(N);
    segtreem stm(N);
    rep(i, N) {
        stM.update(i, P[i]);
        stm.update(i, P[i]);
    }
    
    Unionfind uf(N-K+1);
    rep(i, N-K+1) {
        if (is_sort(i, i+K-1)) sorted.pb(i);
        if (i<N-K) {
            int M = stM.get(i+1, i+K);
            int m = stm.get(i+1, i+K);
            if (P[i]<m && P[i+K]>M) uf.unite(i, i+1);
        }
    }
    rep(i, (int)sorted.size()-1) uf.unite(sorted[i], sorted[i+1]);
    
    rep(i, N-K+1) root.insert(uf.root(i));
    cout << root.size() << endl;
}

Measured memory_bytes: 28512