#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
class rmq {
private:
    int n;
    int sz;
public:
    vector<ll> v;
    rmq(int a){
        n = 1;
        for(; n * 2 < a;){
            n *= 2;
        }
        sz = n * 2;
        v.resize(4 * n - 1, inf);
    }
    
    void update(int i, ll x){
        i += sz - 1;
        v[i] = x;
        while(i > 0){
            i = (i - 1) / 2;
            v[i] = min(v[2 * i + 1], v[2 * i + 2]);//
        }
    }
    
    ll query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return inf;
        if(a <= l && r <= b) return v[k];
        else{
            ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);//
        }
    }
    
    ll query(int a, int b){ // closed interval
        return query(a, b, 0, 0, sz);
    }
};

class rmaq {
private:
    int n;
    int sz;
public:
    vector<ll> v;
    rmaq(int a){
        n = 1;
        for(; n * 2 < a;){
            n *= 2;
        }
        sz = n * 2;
        v.resize(4 * n - 1, -inf);
    }
    
    void update(int i, ll x){
        i += sz - 1;
        v[i] = x;
        while(i > 0){
            i = (i - 1) / 2;
            v[i] = max(v[2 * i + 1], v[2 * i + 2]);//
        }
    }
    
    ll query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return -inf;
        if(a <= l && r <= b) return v[k];
        else{
            ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);//
        }
    }
    
    ll query(int a, int b){ // closed interval
        return query(a, b, 0, 0, sz);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N, K;
    cin >> N >> K;
    
    vector<int> A(N);
    vector<int> B(N - K + 1, 0);
    rep(i, N) cin >> A[i];
    rep(i, N - K + 1) B[i] = i + 1;
    int cnt = 1;
    rep(i, N - 1) {
        if(A[i] < A[i + 1]) {
            cnt++;
        }
        else cnt = 1;
        if(cnt >= K) {
            B[i - K + 2] = 0;
        }
    }
    
    rmq R(N);
    rmaq S(N);
    rep(i, N) {
        R.update(i, A[i]);
        S.update(i, A[i]);
    }
    
    rep(i, N - K) {
//        cout << i  << ":" << A[i] << "," << R.query(i + 1, i + K) << "," << S.query(i + 1, i + K) << "," << A[i + K] << endl;
        if(A[i] < R.query(i + 1, i + K) && S.query(i + 1, i + K) < A[i + K]) {
            B[i + 1] = B[i];
        }
    }
    
    vector<int> C(N + 1, 0);
    rep(i, N - K + 1) {
        C[B[i]] = 1;
    }
    int ans = 0;
    rep(i, N + 1) ans += C[i];
    output(ans);
    

    return 0;
}


Measured memory_bytes: 10752