#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull =  long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

/**
 * 構築 O(NlogN)、クエリ O(1)
 * @tparam T
 */
template<typename T>
class SparseTable {
 private:
  vector<T> values;
  vector<vector<unsigned long>> table;
  vector<unsigned long> msb;
  function<T(T, T)> fn;

  static vector<vector<unsigned long >> build(const vector<T> &values, function<T(T, T)> fn) {
    unsigned long size = (unsigned long) log2(values.size()) + 1;

    vector<vector<unsigned long >> st(values.size(), vector<unsigned long>(size));
    for (unsigned long i = 0; i < values.size(); ++i) st[i][0] = i;
    for (unsigned long p = 1; p < size; ++p) {
      for (unsigned long i = 0; i < values.size(); ++i) {
        unsigned long q = min(i + (1 << (p - 1)), (unsigned long) values.size() - 1);
        unsigned long l = st[i][p - 1];
        unsigned long r = st[q][p - 1];
        if (values[l] == fn(values[l], values[r])) {
          st[i][p] = l;
        } else {
          st[i][p] = r;
        }
      }
    }
    return st;
  }

 public:
  SparseTable(const vector<T> &values, function<T(T, T)> fn) {
    this->values = values;
    this->fn = fn;

    // table[i][p]: [i, i + 2^p) に fn を適用した結果の値のインデックス
    table = build(values, fn);

    // msb[i]: 最上位ビット; どの p を見るべきか
    msb = vector<unsigned long>(values.size() + 1);
    for (unsigned long i = 2; i < values.size() + 1; ++i) {
      msb[i] = msb[i >> 1] + 1;
    }
  }

  /**
   * [a, b) に fn を適用した結果
   */
  T get(unsigned long a, unsigned long b) {
    if (b <= a) throw invalid_argument("a < b でないといけません");
    if (b > values.size()) throw invalid_argument("範囲外です");
    unsigned long p = msb[b - a];
    return fn(values[table[a][p]], values[table[b - (1 << p)][p]]);
  }
};

int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N, K;
  cin >> N >> K;
  vector<ll> P;
  rep (i, N) {
    ll v0;
    cin >> v0;
    P.push_back(v0);
  }

  vector<ll> dp(N, 1);
  repr (i, 1, N) {
    if (P[i - 1] < P[i]) {
      dp[i] = dp[i - 1] + 1;
    }
  }
  ll ans = N - K + 1;

  ll asc_cnt = 0;
  auto st_max = SparseTable<ll>(P, [](ll a, ll b) { return max(a, b); });
  auto st_min = SparseTable<ll>(P, [](ll a, ll b) { return min(a, b); });

  repr (r, K, N) {
    ll l = r - K;
    if (st_min.get(l, r) == P[l] && st_max.get(l + 1, r + 1) == P[r]) {
      ans -= 1;
    } else if (dp[r] >= K) {
      ans -= 1;
      asc_cnt += 1;
    }
  }
  if (dp[K - 1] >= K) {
    ans -= 1;
    asc_cnt += 1;
  }
  if (asc_cnt > 0) {
    ans += 1;
  }
  cout << ans << "\n";

}

Measured memory_bytes: 81520