#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//findのansを確認

class RMQ{
public:
  const ll Inf = 1e9+10;
  ll n=0;
  vector<ll>node;
  RMQ(ll nn){
    n=1;
    while(n<nn)n*=2;
    node.resize(n*2);
    //initializer
    //ex. RMQ
    init(Inf);
  }
  
  void init(ll hoge){//RMQ
    for(int i=0;i<node.size();i++)node[i]=hoge;
  }

  void init(vector<ll> hoge){//RSQ
    for(int i=0;i<hoge.size();i++)update(i,hoge[i]);
  }

  void update(int index,const ll value){
    index+=n;
    node[index]=value;//RMQ
    while(index > 0){
      index/=2;
      node[index] = ope(node[2*index],node[2*index+1]);
    }
  }
  ll find(int l,int r){
    if(l == r) return node[r+n];
    l += n; r += n;
    ll ans = Inf;
    for(; l <= r;l >>=1, r >>=1){
      if(r == l){ans=ope(ans,node[l]); return ans;}
      if(r%2 == 0) ans=ope(ans,node[r]),--r;
      if(l%2) ans=ope(ans,node[l]),++l;
    }
    return ans;
  }
  ll ope(const ll a,const ll b){
    return min(a,b);
  }
};
class RMaxQ{
public:
  const ll Inf = 1e9+10;
  ll n=0;
  vector<ll>node;
  RMaxQ(ll nn){
    n=1;
    while(n<nn)n*=2;
    node.resize(n*2);
    //initializer
    //ex. RMQ
    init(-1);
  }
  
  void init(ll hoge){//RMQ
    for(int i=0;i<node.size();i++)node[i]=hoge;
  }

  void init(vector<ll> hoge){//RSQ
    for(int i=0;i<hoge.size();i++)update(i,hoge[i]);
  }

  void update(int index,const ll value){
    index+=n;
    node[index]=value;//RMQ
    while(index > 0){
      index/=2;
      node[index] = ope(node[2*index],node[2*index+1]);
    }
  }
  ll find(int l,int r){
    if(l == r) return node[r+n];
    l += n; r += n;
    ll ans = -1;
    for(; l <= r;l >>=1, r >>=1){
      if(r == l){ans=ope(ans,node[l]); return ans;}
      if(r%2 == 0) ans=ope(ans,node[r]),--r;
      if(l%2) ans=ope(ans,node[l]),++l;
    }
    return ans;
  }
  ll ope(const ll a,const ll b){
    return max(a,b);
  }
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  ll ans=0;
  vi A;
  A.pb(-llINF);
  RMQ mi(222222);
  RMaxQ ma(222222);
  for(int i=1;i<=n;i++){
    ll a;
    cin>>a;
    A.pb(a);
    mi.update(i-1,A[i]);
    ma.update(i-1,A[i]);
  }
  if(n==k){
    cout<<1<<endl;return 0;
  }
  A.pb(llINF);
  for(int i=2;i<=n-k+1;i++){
    //  cout<<i<<" "<<i+k-2<<endl;
    ll Ma=ma.find(i-1,i+k-3);
    ll Mi=mi.find(i-1,i+k-3);
    //cout<<Ma<<" "<<Mi<<" "<<A[i+k-1]<<" "<<A[i-1]<<endl;
    if(A[i-1]<Mi&&Ma<A[i+k-1]){
    }else{
      ans++;
      //cout<<i<<"!"<<endl;
    }
  }
  vi num;
  ll cnt=1;
  for(int i=2;i<=n;i++){
    if(A[i-1]<A[i]){
      cnt++;
    }else{
      num.pb(cnt);
      cnt=1;
    }
  }
  num.pb(cnt);
  //sort(ALL(num),greater<ll>());
  ll hiki=0;
  cnt=0;
  for(int i=0;i<num.size();i++){
    if(num[i]>=k)cnt++;
  }
  //cout<<ans<<" "<<cnt<<endl;
  cout<<ans+1-max(0LL,cnt-1)<<endl;
  return 0;
}


Measured memory_bytes: 11888