#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

class OnlineIdempotent {
 public:
 	static const int LENGTH_LOG = 20;
 	
 	OnlineIdempotent(vector<LL> &_A, LL (*_operation) (const LL&, const LL&)) {
 		A = _A;
 		operation = _operation;
 		precomputeClosestSmallerPowers();
 		precomputeLogLens();
 		precomputeForPowers();
	}
	
	LL query(int L, int R) {
		int len = closestSmallerPower[R - L + 1];
		return operation(precompute[logLen[len]][L], precompute[logLen[len]][R - len + 1]);
	}
	
 private:
 	
 	void precomputeForPowers() {
 		precompute[0].clear();
 		for (auto &val : A)
 			precompute[0].emplace_back(val);
 		int len = 1, oldlen;
 		for (int power = 1; power < LENGTH_LOG; power++) {
 			oldlen = len;
 			len <<= 1;
 			precompute[power].clear();
 			for (int i = 0; i + len <= A.size(); i++)
 				precompute[power].emplace_back(operation(precompute[power - 1][i], precompute[power - 1][i + oldlen]));
		}
	}
 	
 	void precomputeClosestSmallerPowers() {
 		closestSmallerPower.clear();
 		closestSmallerPower.emplace_back(0);
 		closestSmallerPower.emplace_back(1);
 		for (int len = 2; len <= A.size(); len++)
 			if (closestSmallerPower[len - 1] * 2 > len)
 				closestSmallerPower.emplace_back(closestSmallerPower[len - 1]);
 			else
 				closestSmallerPower.emplace_back(2 * closestSmallerPower[len - 1]);
	}
	
	void precomputeLogLens() {
		logLen.clear();
		logLen.emplace_back(-1);
		logLen.emplace_back(0);
		for (int len = 2; len <= A.size(); len++)
			logLen.emplace_back(1 + logLen[len >> 1]);
	}
 	
 	vector<LL> A;
 	vector<int> closestSmallerPower;
 	vector<int> logLen;
 	vector<LL> precompute[LENGTH_LOG];
 	// This implements the operation used by this class.
 	// It is assumed that the operation OP satisfies
 	// x OP x = x, like it is the case for OP = min.
 	LL (*operation) (const LL&, const LL&);
};



vector<LL> P;
int n, k;

vector<int> lastIncreasing;

LL mymin(const LL& x, const LL& y) {
	return min(x, y);
}

LL mymax(const LL &x, const LL &y) {
	return max(x, y);
}


int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	cin >> n >> k;
	int x;
	FOR (i, n) {
		cin >> x;
		P.eb(x);
	}
	lastIncreasing.eb(0);
	ffor (i, 1, SZ(P))
		if (P[i] > P[i - 1])
			lastIncreasing.eb(lastIncreasing[i - 1]);
		else
			lastIncreasing.eb(i);
			
	OnlineIdempotent onlineMin(P, &mymin);
	OnlineIdempotent onlineMax(P, &mymax);

	int ret = 0;
	bool hasIncreasing = false;
	if (lastIncreasing[k - 1] == 0)
		hasIncreasing = true;
	else
		ret++;
	ffor (i, 1, n - k + 1) {
		if (lastIncreasing[i + k - 1] <= i) {
			hasIncreasing = true;
			continue;
		}
		
		if (onlineMin.query(i - 1, i + k - 2) != P[i - 1] || onlineMax.query(i, i + k - 1) != P[i + k - 1])
			ret++;
	}
		
	ret += hasIncreasing;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 64112