#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#if defined(__GNUC__)
#define LIKELY(x) (__builtin_expect((x), 1))
#define UNLIKELY(x) (__builtin_expect((x), 0))
#else
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#endif  // defined(__GNUC__)

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif  // __DEBUG

template <typename... T>
using tpl = tuple<T...>;

#define DECLARE_TUPLE_ACCESSOR(TIDX) \
  struct TupleIndex_##TIDX##_t {};\
  template <typename... T>\
  typename tuple_element<TIDX, tuple<T...>>::type& operator/(tuple<T...>& t, TupleIndex_##TIDX##_t) { return get<TIDX>(t); }\
  template <typename... T>\
  const typename tuple_element<TIDX, tuple<T...>>::type& operator/(const tuple<T...>& t, TupleIndex_##TIDX##_t) { return get<TIDX>(t); }\
  constexpr TupleIndex_##TIDX##_t _##TIDX;

DECLARE_TUPLE_ACCESSOR(0)
DECLARE_TUPLE_ACCESSOR(1)
DECLARE_TUPLE_ACCESSOR(2)
DECLARE_TUPLE_ACCESSOR(3)

#undef DECLARE_TUPLE_ACCESSOR

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

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

#if __cplusplus > 201402L
template <typename... T, size_t... I>
istream& tupleInputImpl(istream &is, tuple<T...> &tpl, index_sequence<I...>) {
  return (is >> ... >> get<I>(tpl));
}

template <typename... T>
istream& operator>>(istream& is, tuple<T...> &tpl) {
  return tupleInputImpl(is, tpl, index_sequence_for<T...>{});
}
#endif  // __cplusplus > 201402L

//DisjointSet(int n), DisjointSet.initSet(int n)
//DisjointSet.find(int n)
//DisjointSet.isSameSet(int i, int j)
//DisjointSet.merge(int i, int j)
// {{{ Disjoint Set
struct DisjointSet {
  vector<int> pset, setSize;
  int setNum;

  DisjointSet() {}
  DisjointSet(int n) {
    initSet(n);
  }

  void initSet(int n) {
    pset.resize(n);
    setSize.assign(n, 1);
    setNum = n;
    for (int i = 0; i < n; i++) pset[i] = i;
  }

  int find(int n) { return pset[n] == n ? n : (pset[n] = find(pset[n])); }

  bool isSameSet(int i, int j) { return find(i) == find(j); }

  void merge(int i, int j) {
    if(isSameSet(i, j)) return;
    setNum--;
    i = find(i);
    j = find(j);
    if(setSize[i] < setSize[j]) {
      pset[i] = j;
      setSize[j] += setSize[i];
    } else {
      pset[j] = i;
      setSize[i] += setSize[j];
    }
  }
};
// }}}

void Main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  REP(i, n) cin >> a[i];
  set<int> s;
  vi largestToLeft(n);
  REP(i, n) {
    if (i >= k - 1) {
      auto it = end(s); it--;
      if (a[i] > *it) largestToLeft[i - k + 1] = true;
    }
    s.insert(a[i]);
    if (i >= k) s.erase(a[i - k]);
  }
  s.clear();
  vi smallestToRight(n);
  REPD(i, n - 1) {
    if (i + k <= n) {
      if (a[i] < *begin(s)) smallestToRight[i] = true; 
    }
    s.insert(a[i]);
    if (i + k < n) s.erase(a[i + k]);
  }
  int lastViolating = -1e9;
  vi sorted(n);
  FOR(i, 1, n - 1) {
    if (a[i] < a[i - 1]) lastViolating = i;
    if (i >= k - 1) {
      if (lastViolating <= i - k + 1) sorted[i - k + 1] = 1;
    }
  }
  int anySorted = -1;
  REP(i, n) if (sorted[i]) anySorted = i;
  DisjointSet ds(n - k + 1);
  REP(i, n - k + 1) {
    if (sorted[i]) {
      ds.merge(i, anySorted);
      assert(anySorted != -1);
    }
    if (i + k < n && smallestToRight[i] && largestToLeft[i + 1]) ds.merge(i, i + 1);
  }
  cout << ds.setNum << endl;
}

int main(int argc, char *argv[]) {
  if (argc > 1) {
    freopen(argv[1], "r", stdin);
  } else {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
  Main();
}


Measured memory_bytes: 12800