#include <bits/stdc++.h>
using namespace std;

// 0-indexed
// now node k
// child node k*2+1 and k*2+2
// parent node (k-1)/2
struct data {
  int a;
};
const int minint = 0;
data resetdata = {minint};
struct RMQ {
  // except bottom size
  int sizen;
  vector<data> dat;
  RMQ(int newn = 1, data resets = resetdata) {
    reset(newn, resets);
  }
  void reset(int newn = 1, data resets = resetdata) {
    sizen = 1;
    while(sizen < newn) sizen *= 2;
    dat.resize(2 * sizen - 1);
    for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
  }
  // "go up" process
  // data[k].a = newnum
  bool update(int k, int newnum) {
    k += sizen - 1;
    dat[k].a = newnum;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k].a = max(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
    }
    return 1;
  }
  // "go down" process
  // return min number in [a,b)
  // pick(a,b,0,0,sizen)
  int pick(int a, int b, int k = 0, int l = 0, int r = -1) {
    if(r == -1) r = sizen;
    // [l,r)[a,b) or [a,b)[l,r)
    if(r <= a || b <= l) return minint;
    // [a,[l,r),b)
    if(a <= l && r <= b) return dat[k].a;
    // else
    int nowl, nowr, nextlr = k * 2 + 1, med = (l + r) / 2;
    nowl = pick(a, b, nextlr, l, med);
    nowr = pick(a, b, nextlr + 1, med, r);
    return max(nowl, nowr);
  }
};

// 0-indexed
// now node k
// child node k*2+1 and k*2+2
// parent node (k-1)/2
const int maxint = 2147483647;
data resetdata2 = {maxint};
struct RmQ {
  // except bottom size
  int sizen;
  vector<data> dat;
  RmQ(int newn = 1, data resets = resetdata2) {
    reset(newn, resets);
  }
  void reset(int newn = 1, data resets = resetdata2) {
    sizen = 1;
    while(sizen < newn) sizen *= 2;
    dat.resize(2 * sizen - 1);
    for(int i = 0; i < dat.size(); ++i) dat[i] = resets;
  }
  // "go up" process
  // data[k].a = newnum
  bool update(int k, int newnum) {
    k += sizen - 1;
    dat[k].a = newnum;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k].a = min(dat[k * 2 + 1].a, dat[k * 2 + 2].a);
    }
    return 1;
  }
  // "go down" process
  // return min number in [a,b)
  // pick(a,b,0,0,sizen)
  int pick(int a, int b, int k = 0, int l = 0, int r = -1) {
    if(r == -1) r = sizen;
    // [l,r)[a,b) or [a,b)[l,r)
    if(r <= a || b <= l) return maxint;
    // [a,[l,r),b)
    if(a <= l && r <= b) return dat[k].a;
    // else
    int nowl, nowr, nextlr = k * 2 + 1, med = (l + r) / 2;
    nowl = pick(a, b, nextlr, l, med);
    nowr = pick(a, b, nextlr + 1, med, r);
    return min(nowl, nowr);
  }
};

long long n, k;
vector<long long> p, sum;
bool memo[2000005] = {0};
RmQ rmq;
RMQ rMq;

long long solve();

int main() {
  cin >> n >> k;
  p.resize(n);
  for(int i = 0; i < n; ++i) cin >> p[i];

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 1;
  sum.assign(n + 1, 0);
  rMq = RMQ(n);
  rmq = RmQ(n);
  for(int i = 0; i < n; ++i) {
    rMq.update(i, p[i]);
    rmq.update(i, p[i]);
  }
  bool ch = 0;
  for(int i = 0; i < n; ++i) {
    int now = p[i], cnt = 1;
    while(i + 1 < n && now < p[i + 1]) {
      ++i;
      ++cnt;
      now = p[i];
      if(cnt >= k) {
        ch = 1;
        memo[i] = 1;
      }
    }
  }
  ans = 1 - memo[k - 1];
  for(int i = 0; i + k < n; ++i) {
    if((rmq.pick(i, i + k) != p[i] ||
        rMq.pick(i + 1, i + k + 1) != p[i + k]) &&
       !memo[i + k])
      ++ans;
  }
  return ans + ch;
}

Measured memory_bytes: 7680