#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

struct WaveletMatrix {
  struct SuccinctIndexableDictionary {
    size_t length;
    size_t blocks;
    vector<unsigned> bit, sum;
    SuccinctIndexableDictionary() = default;
    SuccinctIndexableDictionary(size_t length)
        : length(length), blocks((length + 31) >> 5) {
      bit.assign(blocks, 0U);
      sum.assign(blocks, 0U);
    }
    void set(int k) { bit[k >> 5] |= 1U << (k & 31); }
    void build() {
      sum[0] = 0U;
      for (size_t i = 1; i < blocks; i++)
        sum[i] = sum[i - 1] + __builtin_popcount(bit[i - 1]);
    }
    bool operator[](int k) { return (bool((bit[k >> 5] >> (k & 31)) & 1)); }
    int rank(int k) {
      return (sum[k >> 5]
              + __builtin_popcount(bit[k >> 5] & ((1U << (k & 31)) - 1)));
    }
    int rank(bool val, int k) { return (val ? rank(k) : k - rank(k)); }
  };

 private:
  unsigned sigma, height;
  size_t length;
  vector<SuccinctIndexableDictionary> matrix;
  vector<int> mid;

 private:
  pair<int, int> succ(bool f, int l, int r, int level) {
    return {matrix[level].rank(f, l) + mid[level] * f,
            matrix[level].rank(f, r) + mid[level] * f};
  }

 public:
  WaveletMatrix() = default;
  WaveletMatrix(vector<int> v)
      : WaveletMatrix(v, *max_element(v.begin(), v.end()) + 1) {}
  WaveletMatrix(vector<int> v, unsigned s) : sigma(s), length(v.size()) {
    height = 32 - __builtin_clz(sigma);
    matrix.resize(height);
    mid.resize(height);
    vector<int> l(length), r(length);
    for (int level = height - 1; level >= 0; level--) {
      matrix[level] = SuccinctIndexableDictionary(length + 1);
      int left = 0, right = 0;
      for (size_t i = 0; i < length; i++) {
        if (((v[i] >> level) & 1))
          matrix[level].set(i), r[right++] = v[i];
        else
          l[left++] = v[i];
      }
      mid[level] = left;
      matrix[level].build();
      v.swap(l);
      for (int i = 0; i < right; i++) v[left + i] = r[i];
    }
  }
  // v[k]
  int access(int k) {
    int ret = 0;
    for (int level = height - 1; level >= 0; level--) {
      bool f = matrix[level][k];
      if (f) ret |= 1 << level;
      k = matrix[level].rank(f, k) + mid[level] * f;
    }
    return ret;
  }
  int operator[](int k) { return access(k); }
  // count i s.t. (0 <= i < r) && v[i] == x
  int rank(int x, int r) {
    int l = 0;
    for (int level = height - 1; level >= 0; level--)
      tie(l, r) = succ((x >> level) & 1, l, r, level);
    return r - l;
  }
  // k-th(0-indexed) smallest number in v[l,r)
  int kth_smallest(int l, int r, int k) {
    assert(0 <= k && k < r - l);
    int ret = 0;
    for (int level = height - 1; level >= 0; level--) {
      int cnt = matrix[level].rank(false, r) - matrix[level].rank(false, l);
      bool f = cnt <= k;
      if (f) ret |= 1 << level, k -= cnt;
      tie(l, r) = succ(f, l, r, level);
    }
    return ret;
  }
  // k-th(0-indexed) largest number in v[l,r)
  int kth_largest(int l, int r, int k) {
    return kth_smallest(l, r, r - l - k - 1);
  }
  // count i s.t. (l <= i < r) && (v[i] < upper)
  int range_freq(int l, int r, int upper) {
    upper = min(upper, (int)sigma);
    int ret = 0;
    for (int level = height - 1; level >= 0; level--) {
      bool f = ((upper >> level) & 1);
      if (f) ret += matrix[level].rank(false, r) - matrix[level].rank(false, l);
      tie(l, r) = succ(f, l, r, level);
    }
    return ret;
  }
  // count i s.t. (l <= i < r) && (lower <= v[i] < upper)
  int range_freq(int l, int r, int lower, int upper) {
    return range_freq(l, r, upper) - range_freq(l, r, lower);
  }
  // max v[i] s.t. (l <= i < r) && (v[i] < upper)
  int prev_value(int l, int r, int upper) {
    int cnt = range_freq(l, r, upper);
    return cnt == 0 ? -1 : kth_smallest(l, r, cnt - 1);
  }
  // min v[i] s.t. (l <= i < r) && (lower <= v[i])
  int next_value(int l, int r, int lower) {
    int cnt = range_freq(l, r, lower);
    return cnt == r - l ? -1 : kth_smallest(l, r, cnt);
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P[i];
  WaveletMatrix wm(P);
  int ans = N - K + 1;
  int cnt = 0;
  int inc = 0;
  for (int i = 1; i < N; i++) {
    if (P[i - 1] < P[i])
      inc++;
    else
      inc = 1;
    if (inc >= K) cnt++;
    if (0 <= i - K + 1 && i + 1 < N) {
      if (inc < K) {
        if (P[i - K + 1] < wm.kth_smallest(i - K + 2, i + 1, 0)
            && P[i + 1] > wm.kth_largest(i - K + 2, i + 1, 0))
          ans--;
      }
    }
  }
  ans -= max(0, cnt - 1);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7936