/*
 * AtCoder AGC038 B Sorting a Segment
*/
#include <bits/stdc++.h>
using namespace std;
int n,k,a[200005],go[200005];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    int ans=0;
    go[0]=0;
    for(int i=2;i<=n;i++){
        if(a[i]>a[i-1])go[i]=go[i-1]+1;
        else go[i]=0;
        if(go[i]>=k-1)ans=1;
    }
    set<int> ss;
    for(int i=1;i<=k;i++)ss.insert(a[i]);
    if(go[k]!=k-1)ans++;
    for(int i=k+1;i<=n;i++){
        ss.insert(a[i]);
        if(*ss.begin()!=a[i-k]||*ss.rbegin()!=a[i]){
            if(go[i]<k-1){
                ans++;
            }
        }
        ss.erase(a[i-k]);
    }
    printf("%d\n",ans);
    return 0;
}