#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cassert>
#include <map>
#include <set>
#include <cctype>
using namespace std;

struct Caclul {
  Caclul(const vector<int>& v) {
    for (int i = 1; i < v.size(); i++) {
      diffs.push_back((v[i] > v[i - 1]) ? 0 : 1);
    }
    for (int i = 0; i < diffs.size(); i++) {
      prefs.push_back((i == 0 ? 0 : prefs[i - 1]) + diffs[i]);
    }
  }

  int GetSum(int l, int r) {
    assert(l <= r);
    if (l == 0) {
      return prefs[r];
    }
    return prefs[r] - prefs[l - 1];
  }

  bool IsSorted(int l, int r) {
    if (l == r) {
      return true;
    }
    return GetSum(l, r - 1) == 0;
  }

  vector<int> diffs;
  vector<int> prefs;
};

const int kMaxN = 2e5 + 2;

struct Sparse {
  Sparse(const vector<int>& v) {
    int n = v.size();
    for (int i = 0; i < n; i++) {
      sp_min_[i][0] = v[i];
      sp_max_[i][0] = v[i];
    }
    for (int j = 1; j < 20; j++) {
      for (int i = 0; i <= n - (1 << j); i++) {
        sp_max_[i][j] = max(sp_max_[i][j - 1], sp_max_[i + (1 << (j - 1))][j-1]);
        sp_min_[i][j] = min(sp_min_[i][j - 1], sp_min_[i + (1 << (j - 1))][j-1]);
      }
    }

    lg_[1] = 0;
    lg_[2] = 1;
    for (int i = 3; i <= n; i++) {
      if ((1 << (lg_[i - 1] + 1)) == i) {
        lg_[i] = lg_[i - 1] + 1;
      } else {
        lg_[i] = lg_[i - 1];
      }
    }
  }

  int GetMin(int l, int r) {
    int v = lg_[r - l + 1];
    return min(sp_min_[l][v], sp_min_[r - (1 << v) + 1][v]);
  }
  int GetMax(int l, int r) {
    int v = lg_[r - l + 1];
    return max(sp_max_[l][v], sp_max_[r - (1 << v) + 1][v]);
  }

  int lg_[kMaxN];
  int sp_min_[kMaxN][20];
  int sp_max_[kMaxN][20];
};

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;

  vector<int> v(n);
  for (auto& el : v) {
    cin >> el;
  }

  Caclul *cc = new Caclul(v);
  Sparse *sps = new Sparse(v);
  auto& c = *cc;
  auto& sp = *sps;
  vector<int> to_s;
  for (int i = 0; i <= n - k; i++) {
    to_s.push_back(i);
  }
  auto comp = [&c, &sp, k](int l0, int l1) {
    if (l0 == l1) {
      return false;
    }
    bool rev_answer = false;

    if (l0 > l1) {
      rev_answer = true;
      swap(l0, l1);
    }

    auto upd = [rev_answer](bool ans) {
      return (rev_answer ? !ans : ans);
    };

    if (l0 + k <= l1) {
      if (!c.IsSorted(l0, l0 + k - 1)) {
        return upd(true);
      }
      if (!c.IsSorted(l1, l1 + k - 1)) {
        return upd(false);
      }
      return false;
    }
    if (!c.IsSorted(l0, l1 - 1)) {
      return upd(true);
    }

    if (sp.GetMax(l0, l1 - 1) > sp.GetMin(l1, l0 + k - 1)) {
      return upd(true);
    }

    if (sp.GetMax(l1, l0 + k - 1) > sp.GetMin(l0 + k, l1 + k - 1)) {
      return upd(false);
    }

    if (!c.IsSorted(l0 + k, l1 + k - 1)) {
      return upd(false);
    }

    return false;
  };

  sort(to_s.begin(), to_s.end(), comp);
  int ans = 0;
  for (int i = 1; i < to_s.size(); i ++) {
    bool a = comp(to_s[i - 1], to_s[i]);
    bool b = comp(to_s[i], to_s[i - 1]);
    assert(a || (!a && !b));
    assert(!(a && b));
    if (a) {
      ans++;
    }
  }
  cout << ans + 1 << endl;

  return 0;
}

Measured memory_bytes: 36212