#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
struct SegTree{
    int n;
    vector <int> node;
    SegTree(vector <int> v){
        int sz = v.size();
        n = 1;
        while(n<sz) n*=2;
        node.resize(2*n-1, INF);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i]; //一番下側
        for(int i=n-2;i>=0;i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
    void update(int number, int val){
        number += n-1;
        node[number]= val;
        while(number>0){
            number=(number-1)/2;
            node[number] = min(node[number*2+1], node[number*2+2]);
        }
    }
    int getmin(int a, int b, int k=0, int l = 0, int r = -1){
        if(r<0) r=n;
        if(r<=a||l>=b) 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);
    }
};
//参考:http://tsutaj.hatenablog.com/entry/2017/03/29/204841
struct maxSegTree{
    int n;
    vector <pair <int,int> > node;
    maxSegTree(vector <int> v){
        int sz = v.size();
        n = 1;
        while(n<sz) n*=2;
        node.resize(2*n-1, {-INF,-INF});
        for(int i=0; i<sz; i++) node[i+n-1] = {v[i],i}; //一番下側
        for(int i=n-2;i>=0;i--) node[i] = max(node[2*i+1], node[2*i+2]);
    }
    int getnum(int p){
        return node[n-1+p].F;
    }
    int geti(int p){
        return node[n-1+p].S;
    }
    void update(int number, int val){
        number += n-1;
        node[number].F= val;
        while(number>0){
            number=(number-1)/2;
            node[number] = max(node[number*2+1], node[number*2+2]);
        }
    }
    pair <int,int> getmax(int a, int b, int k=0, int l = 0, int r = -1){ //0~n
        
        if(r<0) r=n;
        if(r<=a||b<=l) return {-INF,-INF};
        if(a <= l&& r<=b) return node[k];
        pair <int,int>  vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        pair <int,int>  vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
    void showall(){
        for(int i=0;i<2*n-1;i++)cout<<node[i].F<<'&'<<node[i].S<<endl;
    }
};
signed main(void){
    int n,k; cin>>n>>k;
    vector <int> a(n); 
    rep(i,n) cin>>a[i];
    SegTree seg = SegTree(a);
    maxSegTree maxseg = maxSegTree(a);
    itn ans = n-k+1;
    //cout<<ans<<endl;
    for(int i=0;i<n-k;i++){
        if((maxseg.getmax(i+1, i+k+1).F == a[i+k-1 + 1]&&seg.getmin(i,i+k) == a[i])) ans--;
    }
    //cout<<ans<<endl;
    vector <int> cnt(n);
    cnt[0] = 1;
    for(int i=1;i<n;i++){
        if(a[i]>= a[i-1]) cnt[i] = cnt[i-1] + 1;
        else cnt[i] = 1;
    }
    bool sonomama = false;
    rep(i,n) {
        if(cnt[i]==k) {if(!sonomama) sonomama = true; else ans--;}
    }
    //cout<<ans<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 15716