#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> void slideMin(int n, int k, T in[], T res[], void *mem = wmem){
  int i;
  int s = 0;
  T *q;
  int q_st = 0;
  int q_size = 0;
  walloc1d(&q, n);
  for(i=(0);i<(n);i++){
    while(q_size && q[q_st+q_size-1] > in[i]){
      q_size--;
    }
    q[q_st+q_size++] = in[i];
    if(i>=k && in[i-k]==q[q_st]){
      q_st++;
      q_size--;
    }
    if(i>=k-1){
      res[s++] = q[q_st];
    }
  }
}
template<class T> void slideMax(int n, int k, T in[], T res[], void *mem = wmem){
  int i;
  int s = 0;
  T *q;
  int q_st = 0;
  int q_size = 0;
  walloc1d(&q, n);
  for(i=(0);i<(n);i++){
    while(q_size && q[q_st+q_size-1] < in[i]){
      q_size--;
    }
    q[q_st+q_size++] = in[i];
    if(i>=k && in[i-k]==q[q_st]){
      q_st++;
      q_size--;
    }
    if(i>=k-1){
      res[s++] = q[q_st];
    }
  }
}
int N;
int K;
int P[200000];
int up[200000];
int mn[200000];
int mx[200000];
int main(){
  int i;
  wmem = memarr;
  int res = 0;
  int tmp = 0;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(P[Lj4PdHRW]);
    }
  }
  up[0] = 1;
  for(i=(1);i<(N);i++){
    if(P[i] > P[i-1]){
      up[i] =up[i-1] + 1;
    }
    else{
      up[i] =1;
    }
  }
  slideMin(N, K, P, mn);
  slideMax(N, K, P, mx);
  for(i=(0);i<(N-K+1);i++){
    res++;
    if(up[i+K-1] >= K){
      if(tmp){
        res--;
      }
      tmp = 1;
      continue;
    }
    if(i==0){
      continue;
    }
    if(mn[i-1] != P[i-1]){
      continue;
    }
    if(mx[i] != P[i+K-1]){
      continue;
    }
    res--;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int N, K, P[2d5];
// int up[2d5], mn[2d5], mx[2d5];
// {
//   int res = 0, tmp = 0;
//   rd(N,K,P(N));
// 
//   up[0] = 1;
//   rep(i,1,N) up[i] = if[P[i] > P[i-1], up[i-1] + 1, 1];
// 
//   slideMin(N, K, P, mn);
//   slideMax(N, K, P, mx);
// 
//   rep(i,N-K+1){
//     res++;
//     if(up[i+K-1] >= K){
//       if(tmp) res--;
//       tmp = 1;
//       continue;
//     }
//     if(i==0) continue;
// 
//     if(mn[i-1] != P[i-1]) continue;
//     if(mx[i] != P[i+K-1]) continue;
//     res--;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 4352