#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 200005;
int n,k,seg_size;

int P[n_max];
int syou[n_max * 4];
int dai[n_max * 4];

void update(int i,int x){
    i += seg_size - 1;
    syou[i] = x;
    while(i > 0){
        i = (i-1) / 2;
        syou[i] = min(syou[i*2 + 1],syou[i* 2 + 2]);
    }
}

void update2(int i,int x){
    i += seg_size - 1;
    dai[i] = x;
    while(i > 0){
        i = (i-1) / 2;
        dai[i] = max(dai[i*2 + 1],dai[i* 2 + 2]);
    }
}


int query(int a,int b ,int k,int l,int r){
    if(r <= a or b <= l) return INF;
    if(a <= l and r<= b) return syou[k];
    else{
        int vl = query(a,b,k*2 + 1,l,(l+r)/2);
        int vr = query(a,b,k*2 + 2,(l+r)/2,r);
        return min(vl,vr);
    }
}

int query2(int a,int b ,int k,int l,int r){
    if(r <= a or b <= l) return - INF;
    if(a <= l and r<= b) return dai[k];
    else{
        int vl = query2(a,b,k*2 + 1,l,(l+r)/2);
        int vr = query2(a,b,k*2 + 2,(l+r)/2,r);
        return max(vl,vr);
    }
}



signed main(){
    cin >> n >> k;
    seg_size = 1;
    while(seg_size < n){
        seg_size *= 2;
    }
    REP(i,n * 4){
        dai[i] = - INF;
        syou[i] = INF;
    }
    REP(i,n) cin >> P[i];
    REP(i,n){
        update(i,P[i]);
        update2(i,P[i]);
    }


    int cnt = 0;
    int id = 0;
    int kosuu = 0;
    bool is_syoujun[n];
    REP(i,n) is_syoujun[i] = false;
    FOR(i,1,n){
        if(P[i] < P[i-1]){
            if(kosuu >= k){
                FOR(j,id,id + 1 + kosuu - k) is_syoujun[j] = true;
            }
            kosuu = 0;
        }
        else{
            if(kosuu == 0){
                id = i -1;
                kosuu = 2;
            }
            else kosuu ++;
        }
    }
    if(kosuu >= k){
        FOR(j,id,id + 1 + kosuu - k) is_syoujun[j] = true;
    }

    bool hoge = false;
    int ans = 0;
    if(is_syoujun[0])hoge = true;
    else ans = 1;
    FOR(i,1,n){
        if(i + k - 1 >= n) break;
        if(is_syoujun[i]) hoge = true;
        else{
            if(query(i-1,i-1 + k,0,0,seg_size) ==P[i-1]  and query2(i,i+k,0,0,seg_size) ==P[i+k-1] ) continue;
            ans ++;
        }
    }

    cout << ans + int(hoge) << endl;


        




}

Measured memory_bytes: 14592