// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

template < typename Value, typename Cmp = std::less< Value > >
class sliding_minimum {
    std::deque< Value > que;

    void pop_left_until(int target) {
      assert(target <= right);
      while (left < target)
        { shrink(); }
    }
    void push_right_until(int target) {
      assert(target <= n);
      while (right < target)
        { extend(); }
    }

  public:
    int                  n;
    std::vector< Value > v;
    Cmp             cmp;
    int                 left, right;

    sliding_minimum(std::vector< Value > const& v) :
      n    (v.size()),
      v    (v),
      cmp  (Cmp()),
      left (0),
      right(0)
      {}

    auto get_left_index()  const { return left; }
    auto get_right_index() const { return right; }

    auto query_index() const
      { assert(!que.empty()); return que.front(); }
    auto query() const
      { return v.at(query_index()); }

    void shrink() {
      if (que.front() == left++)
        { que.pop_front(); }
      assert(left <= right);
    }
    void extend() {
      while (!que.empty() && !cmp(v.at(que.back()), v.at(right)))
        { que.pop_back(); }
      que.push_back(right++);
      assert(right <= n);
    }
    void slide()
      { shrink(); extend(); }
    void move(int l, int r) {
      push_right_until(r);
      pop_left_until(l);
    }
};

template < typename Container,
  typename Value = typename Container::value_type,
  std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr
>
std::istream& operator>> (std::istream& is, Container& v) {
  for (auto & x : v) is >> x;
  return is;
}

template < typename Container,
  typename Value = typename Container::value_type,
  std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr
>
std::ostream& operator<< (std::ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, k; std::cin >> n >> k;
  std::vector< int > a(n); std::cin >> a;
  if (n == k) {
    std::cout << 1 << std::endl;
    return 0;
  }

  auto cmp = 0;
  std::vector< int > c(n, 0);
  rep(i, 1, n)
    { c.at(i) = c.at(i - 1) + (a.at(i - 1) > a.at(i)); }
  auto flat = std::vector< int >(n - k + 1, 0);
  rep(i, 0, n - k + 1) {
    auto j = i + k - 1;
    flat.at(i) = c.at(i) == c.at(j);
  }
  flat.insert(flat.begin(), 0);
  rep(i, 1, n - k + 2)
    { cmp += flat.at(i - 1) == 0 && flat.at(i) == 1; }

  auto slmin = sliding_minimum< int >(a);
  auto slmax = sliding_minimum< int, std::greater< int > >(a);
  slmin.move(0, k + 1);
  slmax.move(0, k + 1);
  auto ret = 0;
  rep(i, 0, n - k) {
    auto j = i + k;
    auto same = i == slmin.query_index() && j == slmax.query_index();
    if (!same)
      { ret++; }
    if (j == n - 1)
      { break; }
    slmin.slide();
    slmax.slide();
  }
  ret++;
  ret -= std::max(cmp - 1, 0);
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 4272