#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif

struct SegTree {
  private:
    int n;
    vector<int> node_min, node_max;
  public:
    SegTree(int size) {
      n = 1;
      while (n < size) n *= 2;
      node_min.resize(2*n-1, INF); node_max.resize(2*n-1, -INF);
    }
    void update(int index, int value) {
      index = n - 1 + index;
      node_min[index] = node_max[index] = value;
      while (index != 0) {
        index = (index-1) / 2;
        node_min[index] = min(node_min[2*index+1], node_min[2*index+2]);
        node_max[index] = max(node_max[2*index+1], node_max[2*index+2]);
      }
    }
    int get_max(int left, int right, int k = 0, int l = 0, int r = -1) {
      if (r < 0) r = n;
      if (r <= left || right <= l) return -INF;
      if (left <= l && r <= right) return node_max[k];
      int vl = get_max(left, right, 2*k+1, l, (l+r)/2);
      int vr = get_max(left, right, 2*k+2, (l+r)/2, r);
      return max(vl, vr);
    }
    int get_min(int left, int right, int k = 0, int l = 0, int r = -1) {
      if (r < 0) r = n;
      if (r <= left || right <= l) return INF;
      if (left <= l && r <= right) return node_min[k];
      int vl = get_min(left, right, 2*k+1, l, (l+r)/2);
      int vr = get_min(left, right, 2*k+2, (l+r)/2, r);
      return min(vl, vr);
    }
};

int main() {
  int N, K; cin >> N >> K;

  int P[N];
  SegTree T(N);
  rep(i, N) {
    cin >> P[i];
    T.update(i, P[i]);
  }
  int count[N];
  count[0] = 0;
  rep(i, N-1) {
    count[i+1] = count[i] + (P[i] > P[i+1]);
  }
  int ans = 1;
  // 最初の区間がソートされているか?
  bool flag = count[K-1]>0;
  rep(i, N-K) {
    // [i, i+K)を見たい
    if ((flag || count[i+K] - count[i+1] > 0) &&
        (P[i] != T.get_min(i, i+K+1) || T.get_max(i, i+K+1) != P[i+K])) {
      if (count[i+K] - count[i+1] == 0)
        flag = false;
      ++ans;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5888