#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

template <typename T>
struct MaxSegTree {
  ll n, ofst;
  vector<T> arr;

  MaxSegTree(const ll _n) {
    n = 1;
    while (n < 2 * _n) n <<= 1;
    arr.resize(n, 0);
    ofst = n >> 1;
  }

  void update(ll i, T x) {
    i += ofst;
    arr[i] = x;
    while (true) {
      i /= 2;
      if (i == 0) break;
      arr[i] = max(arr[2 * i], arr[2 * i + 1]);
    }
  }

  T get(ll l, ll r) {
    T ret = 0;
    l += ofst, r += ofst + 1;
    while (l < r) {
      if (l % 2 == 1) {
        chmax(ret, arr[l]);
        l++;
      }
      l /= 2;
      if (r % 2 == 1) {
        chmax(ret, arr[r - 1]);
        r--;
      }
      r /= 2;
    }
    return ret;
  }
};

template <typename T>
struct MinSegTree {
  ll n, ofst;
  vector<T> arr;

  MinSegTree(const ll _n) {
    n = 1;
    while (n < 2 * _n) n <<= 1;
    arr.resize(n, 0);
    ofst = n >> 1;
  }

  void update(ll i, T x) {
    i += ofst;
    arr[i] = x;
    while (true) {
      i /= 2;
      if (i == 0) break;
      arr[i] = min(arr[2 * i], arr[2 * i + 1]);
    }
  }

  T get(ll l, ll r) {
    T ret = INF;
    l += ofst, r += ofst + 1;
    while (l < r) {
      if (l % 2 == 1) {
        chmin(ret, arr[l]);
        l++;
      }
      l /= 2;
      if (r % 2 == 1) {
        chmin(ret, arr[r - 1]);
        r--;
      }
      r /= 2;
    }
    return ret;
  }
};

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  MaxSegTree<ll> maxseg(n);
  MinSegTree<ll> minseg(n);
  vll ps(n), stchk(n);

  ll cur = 0;
  rep(i, n) {
    ll p;
    cin >> p;
    ps[i] = p;
    maxseg.update(i, p);
    minseg.update(i, p);
    if (i > 0 && ps[i] > ps[i - 1]) {
      cur++;
    } else {
      cur = 0;
    }
    stchk[i] = cur;
  }

  ll ans = n - k + 1;
  bool sortedoccur = false;
  repLRE(i, 0, n - k) {
    if (sortedoccur) {
      if (stchk[i + k - 1] >= k - 1) {
        ans--;
        continue;
      }
    } else {
      if (stchk[i + k - 1] >= k - 1) sortedoccur = true;
    }
    if (i > 0) {
      ll minv = minseg.get(i - 1, i + k - 2);
      bool conda = ps[i - 1] == minv;
      ll maxv = maxseg.get(i, i + k - 1);
      bool condb = ps[i + k - 1] == maxv;
      if (conda && condb) ans--;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 14616