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

class UnionFind {
 private:
  vector<long long> parents;
  vector<long long> ranks;
  vector<long long> sizes;

 public:
  explicit UnionFind(long long size) :
      parents(size),
      ranks(size, 0),
      sizes(size, 1) {
    for (long long i = 0; i < size; ++i) parents[i] = i;
  }

  void unite(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    // rank が小さい方が下
    if (ranks[x] > ranks[y]) {
      // x が root
      parents[y] = x;
      sizes[x] += sizes[y];
    } else {
      // y が root
      parents[x] = y;
      sizes[y] += sizes[x];
      if (ranks[x] == ranks[y]) ranks[y]++;
    }
  }

  long long root(long long x) {
    if (parents[x] == x) return x;
    return parents[x] = root(parents[x]);
  }

  long long size(long long x) {
    return sizes[root(x)];
  }
};

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

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

    vector<vector<long >> st(values.size(), vector<long>(size, 0));
    for (long i = 0; i < values.size(); ++i) st[i][0] = i;
    for (long p = 1; p < size; ++p) {
      for (long i = 0; i < values.size(); ++i) {
        long q = min(i + (1 << (p - 1)), (long) values.size() - 1);
        long l = st[i][p - 1];
        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<long>(values.size() + 1, 0);
    for (long i = 2; i < values.size() + 1; ++i) {
      msb[i] = msb[i >> 1] + 1;
    }
  }

  /**
   * [a, b) に fn を適用した結果
   */
  T get(long a, long b) {
    if (b <= a) throw invalid_argument("a < b でないといけません");
    if (b > values.size()) throw invalid_argument("範囲外です");
    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);
  }

  auto uf = UnionFind(N);

  vector<ll> dp(N, 1);
  repr (i, 1, N) {
    if (P[i] > P[i - 1]) {
      dp[i] = dp[i - 1] + 1;
    }
  }
  auto m = max_element(all(dp));
  if (*m >= K) {
    auto b = m - dp.begin();
    rep (i, N) {
      if (dp[i] >= K) {
        uf.unite(b - K + 1, i - K + 1);
      }
    }
  }

  deque<ll> min_from(N, 0);
  deque<ll> max_from(N, 0);
  deque<ll> mins;
  deque<ll> maxs;
  rep (i, N) {
    while (!mins.empty() && P[i] < P[mins.back()]) {
      mins.pop_back();
    }
    mins.push_back(i);
    while (mins.front() <= i - K - 1) {
      mins.pop_front();
    }

    while (!maxs.empty() && P[i] > P[maxs.back()]) {
      maxs.pop_back();
    }
    maxs.push_back(i);
    while (maxs.front() <= i - K - 1) {
      maxs.pop_front();
    }

    if (i - K >= 0) {
      min_from[i - K] = P[mins.front()];
      max_from[i - K] = P[maxs.front()];
    }
  }

  rep (i, N - K) {
    ll mi = min_from[i];
    ll ma = max_from[i];
    if (mi == P[i] && ma == P[i + K]) {
      uf.unite(i, i + 1);
    }
  }

  unordered_set<ll> roots;
  rep (i, N - K + 1) {
    roots.insert(uf.root(i));
  }
  cout << roots.size() << "\n";
}

Measured memory_bytes: 19568