#include <stdio.h>
#include <algorithm>
#include <set>
using namespace std;
using ll = long long;
int n, k, p[200010], ord[200010];
set<int> s;
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", p + i);
	for (int i = 0; i < k; i++)
		s.emplace(p[i]);
	for (int i = n - 2; 0 <= i; i--) {
		if (p[i] < p[i + 1])
			ord[i] = ord[i + 1] + 1;
		else
			ord[i] = 0;
	}

	int cnt = n - k + 1, unc = k - 1 <= ord[0];

	for (int i = 0; i + k < n; i++) {
		bool valid = true;
		valid &= (*s.begin()) == p[i];
		s.erase(p[i]);
		s.emplace(p[i + k]);
		valid &= (*s.rbegin()) == p[i + k];

		bool isunc = k - 1 <= ord[i + 1];
		if (1 <= unc && isunc)
			valid = true;
		if (isunc)
			unc = 1;

		if (valid)
			cnt--;
	}
	printf("%d\n", cnt);
}