#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct SegmentTree {
private:
    int n;
    vector<int> node;
 
public:
    SegmentTree() {
        int sz = 200010;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);
        for(int i=0; i<sz; i++) node[i+n-1] = 1e8;
        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]);
        }
    }
    // hannkaikukann 
    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 INF;
        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);
    }
};

int P[200050];
int Q[200050];
int Left[200050];
int Right[200050];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    SegmentTree seg;
    SegmentTree seg2;
    int N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        Q[N - 1 - i] = N + 1 - P[i];
        seg.update(i, P[i]);
    }
    for(int i = 0; i < N; i++) {
        seg2.update(i, Q[i]);
    }
    for(int i = 0; i < K; i++) {
        if(seg.getmin(i,K) == P[i]) {
            Left[0]++;
        }
        else break;
    }
    for(int i = 1; i + K <= N; i++) {
        if(Left[i-1] == 0) {
            for(int j = i; j < i + K; j++) {
                if(seg.getmin(j, i + K) == P[j]) {
                    Left[i]++;
                } else break;
            }
        } else if(Left[i-1] == K && P[i+K-1] > P[i+K-2]) {
            Left[i] = K;
        } else {
            int ok = 0;
            int ng = Left[i-1];
            while(ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if(P[i + mid - 1] < P[i+K-1]) ok = mid;
                else ng = mid;
            }
            Left[i] = ok;
        }
    }
    for(int i = 0; i < N; i++) cerr << Q[i] << " ";
    cerr << endl;
    for(int i = 0; i < K; i++) {
        if(seg2.getmin(i,K) == Q[i]) {
            Right[0]++;
        }
        else break;
    }
    for(int i = 1; i + K <= N; i++) {
        if(Right[i-1] == 0) {
            for(int j = i; j < i + K; j++) {
                if(seg2.getmin(j, i + K) == Q[j]) {
                    Right[i]++;
                } else break;
            }
        } else if(Right[i-1] == K && Q[i+K-1] > Q[i+K-2]) {
            Right[i] = K;
        } else {
            int ok = 0;
            int ng = Right[i-1];
            while(ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if(Q[i + mid - 1] < Q[i+K-1]) ok = mid;
                else ng = mid;
            }
            //cerr << "A:" << i << " " << ok << endl;
            Right[i] = ok;
        }
    }
    /*
    for(int i = 0; i < N; i++) cerr << i << " " << Left[i] << endl;
    for(int i = 0; i < N; i++) cerr << i << " " << Right[i] << endl;
    */
    set<i_i> st;
    for(int i = 0; i <= N - K; i++) {
        int j = N - K - i;
        if(Left[i] == K) {
            st.insert({0, 0});
        } else {
            int l = i + Left[i];
            int r = N - j - Right[j];
            st.insert({l, r});
        }
    }
    cout << st.size() << endl;
    /*
    int ans = N - K + 1;
    for(int i = 0; i + K < N; i++) {
        int val = seg.getmin(i, i + K);
        if(val != P[i]) continue;
        val = seg2.getmin(i + 1, i + 1 + K);
        if(-val != P[i+K]) continue;
        cerr << i << endl;
        ans--;
    }
    */
    return 0;
}


Measured memory_bytes: 16896