#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll sor[ohara];
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------

struct SegmentTreemi{
    int siz;
    vector<ll> node;
    SegmentTreemi(int n,ll init){
        siz=1;
        while(siz<n)siz<<=1;
        node.assign(2*siz,init);
    }
 
    void update(int k,ll x){
        k+=siz-1;
        node[k]=x;
        while(k>0){
            k=(k-1)/2;
            node[k]=min(node[2*k+1],node[2*k+2]);
        }
    }
 
    ll query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=siz;
        if(r<=a||b<=l)return LINF;
        if(a<=l&&r<=b)return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

struct SegmentTreema{
    int siz;
    vector<ll> node;
    SegmentTreema(int n,ll init){
        siz=1;
        while(siz<n)siz<<=1;
        node.assign(2*siz,init);
    }
 
    void update(int k,ll x){
        k+=siz-1;
        node[k]=x;
        while(k>0){
            k=(k-1)/2;
            node[k]=max(node[2*k+1],node[2*k+2]);
        }
    }
 
    ll query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=siz;
        if(r<=a||b<=l)return -LINF;
        if(a<=l&&r<=b)return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    SegmentTreema ma(ohara,-LINF);
    SegmentTreemi mi(ohara,LINF);
    rep(i,n-1){
        if(a[i]<a[i+1]){
            sor[i]=1;
        }
    }
    rrrep(i,n-2,0){
        if(sor[i]!=0)sor[i]+=sor[i+1];
    }
    ans=1;
    if(sor[0]>=k-1){
        fl=true;
    }
    rep(i,n){
        ma.update(i,a[i]);
        mi.update(i,a[i]);
        //Cout(a[i]);
    }
    rrep(i,1,n-k+1){
        ll mi1,ma1;
        mi1=mi.query(i,i+k-1);
        ma1=ma.query(i,i+k-1);
        //cout<<i<<" "<<mi1<<" "<<ma1<<"\n";
        if(a[i-1]<mi1&&ma1<a[i+k-1])continue;
        if(sor[i]>=k-1){
            if(!fl){
                fl=true;
                ans++;
                continue;
            }
            else continue;
        }
        ans++;
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 38656