#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <stack>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
class sliding_window_aggregation {
public:
  using value_type = typename T::value_type;
  using value_operation = typename T::value_operation;
  using size_type = unsigned;

private:
  struct node {
    value_type value, sum;
    node (const value_type &value_, const value_type &sum_): value(value_), sum(sum_) { }
  };
  const value_operation op;
  std::stack<node> front, back;

public:
  sliding_window_aggregation(): op(value_operation()), front(), back() { }

  value_type fold() const {
    if (front.empty()) {
      return back.top().sum;
    } 
    else if (back.empty()) {
      return front.top().sum;
    } 
    else {
      return op(front.top().sum, back.top().sum);
    }
  }

  size_type size() const {
    return front.size() + back.size();
  }
  
  bool empty() const {
    return size() == 0;
  }

  void push(const value_type &x) {
    if (back.empty()) {
      back.emplace(x, x);
    } 
    else {
      value_type tmp = op(back.top().sum, x);
      back.emplace(x, tmp);
    }
  }

  void pop() {
    if (front.empty()) {
      front.emplace(back.top().value, back.top().value);
      back.pop();
      while (!back.empty()) {
        value_type tmp = op(back.top().value, front.top().sum);
        front.emplace(back.top().value, tmp);
        back.pop();
      }
    }
    front.pop();
  }

};

template <class T>
struct range_max {
  using value_type = T;
  struct value_operation {
    value_type operator () (const value_type &x, const value_type &y) const {
      return x > y ? x : y;
    }
  };
};

template <class T>
struct range_min {
  using value_type = T;
  struct value_operation {
    value_type operator () (const value_type &x, const value_type &y) const {
      return x < y ? x : y;
    }
  };
};

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> A(N);
  for (int &x: A) {
    std::cin >> x;
  }
  sliding_window_aggregation<range_max<int>> max;
  sliding_window_aggregation<range_min<int>> min;
  std::vector<int> parent(N - K + 1);
  std::iota(parent.begin(), parent.end(), 0);
  for (int i: range(1, K)) {
    max.push(A[i]);
    min.push(A[i]);
  }
  for (int i: range(0, N - K)) {
    if (A[i] < min.fold() && max.fold() < A[i + K]) {
      parent[i + 1] = parent[i];
    }
    max.pop();
    min.pop();
    max.push(A[i + K]);
    min.push(A[i + K]);
  }
  std::vector<bool> sorted(N - K + 1);
  {
    int l, r;
    int last = N;
    for (int i: range(0, N)) {
      if (last > A[i]) {
        l = i;
        r = i + 1;
      }
      else {
        ++r;
      }
      if (r - l >= K) {
        sorted[r - K] = true;
      }
      last = A[i];
    }
  }
  int ans = 0;
  bool flag = false;
  for (int i: range(0, N - K + 1)) {
    if (parent[i] != i) {
      continue;
    }
    if (sorted[i]) {
      flag = true;
    }
    else {
      ++ans;
    }
  }
  std::cout << ans + (flag ? 1 : 0) << '\n';
  return 0;
}


Measured memory_bytes: 4352