#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

ll nn=262144;
vll maxval(nn*2-1,0);
vll minval(nn*2-1,200001);

void maxup(ll i,ll x){
    i+=nn-1;
    maxval[i]=x;
    while(i>0){
        i=(i-1)/2;
        maxval[i]=max(maxval[i*2+1],maxval[i*2+2]);
    }
}
void minup(ll i,ll x){
    i+=nn-1;
    minval[i]=x;
    while(i>0){
        i=(i-1)/2;
        minval[i]=min(minval[i*2+1],minval[i*2+2]);
    }
}
ll maxq(ll a,ll b,ll k,ll l,ll r) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return maxval[k];
    else {
        ll c1 = maxq(a, b, 2 * k + 1, l, (l + r) / 2);
        ll c2 = maxq(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(c1, c2);
    }
}
ll minq(ll a,ll b,ll k,ll l,ll r) {
    if (r <= a || b <= l) return 200001;
    if (a <= l && r <= b) return minval[k];
    else {
        ll c1 = minq(a, b, 2 * k + 1, l, (l + r) / 2);
        ll c2 = minq(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(c1, c2);
    }
}

signed main(){
    llin(n);
    llin(k);
    vllin(p,n);
    FOR(i,0,n-1){
        maxup(i,p[i]);
        minup(i,p[i]);
    }
    vll u(n,0);
    FOR(i,0,n-k-1){
        if(minq(i+1,i+k+1,0,0,nn)<p[i]|maxq(i,i+k,0,0,nn)>p[i+k]){
            u[i]=1;
        }
    }
    u[n-k]=1;
    ll v=0;
    ll w=0;
    FOR(i,0,n-2){
        if(p[i]<p[i+1]) v++;
        else v=0;
        if(v>=k-1){
            w=1;
            u[i-k+2]=0;
        }
    }
    FOR(i,0,n-k){
        w+=u[i];
    }
    sal(w)
}


Measured memory_bytes: 11520