#include "bits/stdc++.h"

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
#include "bits/stdc++.h"

struct RMQ {
  using t = int;
  constexpr static t id() { return std::numeric_limits<t>::min(); }
  static t op(const t &a, const t &b) { return std::max(a, b); }
};

struct RmQ {
  using t = int;
  constexpr static t id() { return std::numeric_limits<t>::max(); }
  static t op(const t &a, const t &b) { return std::min(a, b); }
};

template <typename M> struct SegmentTree {
  int n;
  using T = typename M::t;
  std::vector<T> nodes;

  SegmentTree(std::vector<T> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz)
      n *= 2;
    nodes.resize(2 * n - 1, M::id());
    for (int i = 0; i < sz; i++)
      nodes[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      nodes[i] = M::op(nodes[i * 2 + 1], nodes[i * 2 + 2]);
  }
  SegmentTree(int _n) {
    n = 1;
    while (n < _n)
      n *= 2;
    nodes.resize(2 * n - 1, M::id());
  }
  void update(int k, T a) {
    k += n - 1;
    nodes[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      nodes[k] = M::op(nodes[2 * k + 1], nodes[2 * k + 2]);
    }
  }
  T get(int k) { return nodes[k + n - 1]; }
  T query(int a, int b) { return query(a, b, 0, 0, n); }

private:
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return M::id();
    if (a <= l && r <= b)
      return nodes[k];
    else {
      T vl = query(a, b, 2 * k + 1, l, (r + l) / 2),
        vr = query(a, b, 2 * k + 2, (r + l) / 2, r);
      return M::op(vl, vr);
    }
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vi v(n);
  REP(i, n) cin >> v[i];

  set<pii> st;
  int pos = -1, prev = INF;
  REP(i, n) {
    if (prev > v[i]) {
      st.insert({pos, i});
      pos = i;
      prev = v[i];
    } else {
      prev = v[i];
    }
  }
  st.insert({pos, n});
  vi sorted(n - k + 1, 0);
  REP(i, n - k + 1) {
    auto c = st.lower_bound({i, INF});
    c--;
    auto p = *c;
    if (p.second - i >= k)
      sorted[i] = 1;
  }
  int ans = 1;
  SegmentTree<RmQ> st1(v);
  SegmentTree<RMQ> st2(v);
  FOR(i, 1, n - k + 1) {
    if (!sorted[i] && (st1.query(i - 1, i + k - 1) != v[i - 1] ||
        st2.query(i, i + k) != v[i + k - 1]))
      ans++;
  }
  if (sorted[0] == 0 && *max_element(ALL(sorted)) == 1)ans++;
  cout << ans << endl;
}


Measured memory_bytes: 11376