// #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

class union_find {
    int n;
    std::vector<int> prt;

  public:
    union_find (int n) : n(n), prt(n, -1){}

    bool is_root (int x)        const {return prt.at(x) < 0;}
    int  size    (int x)        const {return -prt.at(find(x));}
    bool same(int x, int y)     const {return find(x) == find(y);}
    int  find    (int x)        const {
      while (!is_root(x)) x = prt.at(x);
      return x;
    }
    // Returns `true` if x and y are newly connected.
    // The smaller one x becomes a child of the larger one y.
    bool unite   (int x, int y) {
      if ((x = find(x)) == (y = find(y))) return false;
      if (size(x) > size(y)) std::swap(x, y);
      prt.at(y) += prt.at(x);
      prt.at(x) = y;
      return true;
    }
};

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 N = n - k + 1;
  auto uf = union_find(N + 1);

  std::vector< int > c(n, 0);
  rep(i, 1, n)
    { c.at(i) = c.at(i - 1) + (a.at(i - 1) > a.at(i)); }
  rep(i, 0, N) {
    auto j = i + k - 1;
    if (c.at(i) == c.at(j))
      { uf.unite(i, N); }
  }

  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 - 1) {
    auto j = i + k;
    if (i == slmin.query_index() && j == slmax.query_index())
      { uf.unite(i, i + 1); }
    if (i == N - 2)
      { break; }
    slmin.slide();
    slmax.slide();
  }
  ret = 0;
  rep(i, 0, N)
    { ret += uf.is_root(i); }
  ret += (uf.size(N) > 1);
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 4224