/* 
 Author:N_o_o_B 
 Created:September 21 2019 17:21:16
*/
#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll; 
#define all(x) x.begin(),x.end()
#define endl '\n'
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
const ll mod=1e9+7;
const ll INF=1e18;
const int maxn=2e5+5;
vi tree(4*maxn),tree2(4*maxn);
vi a(maxn);
void build(int v,int l,int r){
    if(l==r){
        tree[v]=a[l];
        tree2[v]=a[l];
        return;
    }
    int mid=(l+r)>>1;
    build(2*v,l,mid);
    build(2*v+1,mid+1,r);
    tree[v]=max(tree[2*v],tree[2*v+1]);
    tree2[v]=min(tree2[2*v],tree2[2*v+1]);
    
}
pii query(int v,int l,int r,int ql,int qr){
    if(l>qr or ql>r) return {-1e9,1e9};
    if(l>=ql and r<=qr) return {tree[v],tree2[v]};
    int mid=(l+r)>>1;
    pii p1=query(2*v,l,mid,ql,qr);
    pii p2=query(2*v+1,mid+1,r,ql,qr);
    pii p={max(p1.first,p2.first),min(p1.second,p2.second)};
    return p;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> a[i];
    vl dp(n);
    dp[n-1]=1;
    for(int i=n-2;i>=0;i--){
        if(a[i+1]<a[i]) dp[i]=1;
        else dp[i]=dp[i+1]+1;
    }
    build(1,0,n-1);
    ll ans=0;
    bool fl=0;
    for(int i=0;i<=n-k;i++){
        if(dp[i]>=k) fl=1;
        else {
            pii p=query(1,0,n-1,i,i+k-1);
           // trace(p);
            if(p.second==a[i]){
             //   trace(i,a[i+k],p.first);
                if(i+k==n or a[i+k]<p.first) {ans++;}
            }
            else ans++;
        }
    }
    ans+=fl;
    // set<vector<int>> s;
    // for(int i=0;i<=n-k;i++){
    //     vector<int> b;
    //     for(int i=0;i<n;i++) b.push_back(a[i]);
    //     sort(b.begin()+i,b.begin()+i+k);
    //     s.insert(b);
    // }
    // cout << s.size() << endl;
    // for(auto x:s) trace(x);
    cout << ans << endl;
    time_taken();
    return 0;
}

Measured memory_bytes: 8832