#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n,k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i,n)cin >> v[i];
  set<int> st;
  rep(i,k)st.insert(v[i]);
  int res = 1;
  for(int i = k;i < n;i++){
    if(*st.begin() == v[i-k]){
      if(*st.rbegin() > v[i])res++;
    }else{
      res++;
    }
    st.erase(v[i-k]);
    st.insert(v[i]);
  }
  int cnt = 0,s = 0;
  rep(i,n){
    if(i == 0 || v[i-1] < v[i])cnt++;
    else {
      if(cnt >= k)s++;
      cnt = 1;
    }
  }
  if(cnt >= k)s++;
  cout << (s != 0 ? res-s+1 : res) << endl;





  return 0;
}