#include <cstdio>

const int N = 800005, VAL = 500000;

int mg, n, l, a[N], aib[2 * VAL + 5];

void read() {
	scanf("%d%d", &n, &l);
	
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		if (a[i] > mg)
			mg = a[i];
	}
}

inline int bit(int x) {
	return (x & (- x));
}
 
void insert_aib(int val) {
	while (val) {
		++ aib[val];
		val -= bit(val);
	}
}

void erase_aib(int val) {
	while (val) {
		-- aib[val];
		val -= bit(val);
	}
}

int query_aib(int val) {
	int rez = 0;
	
	while (val <= mg) {
		rez += aib[val];
		val += bit(val);
	}
	
	return rez;
}

void init() {
	for (int i = 1; i <= n; ++ i)
		a[i] += VAL;
	
	mg += VAL;
	
	a[0] = 1;
	insert_aib(a[0]);
	
	for (int i = 1; i <= 2 * l; ++ i)
		insert_aib(a[i]);
}

void solve() {
	int v = 0, nrs = 0;
	
	for(int pi = 1; pi + 2 * l <= n; ++ pi) {
		erase_aib(a[pi - 1]);
		insert_aib(a[pi + 2 * l]);
		v = query_aib(a[pi + l]);
		if (v == l + 1)
			++ nrs;
	}
	
	printf("%d\n", nrs);
}

int main() {
	freopen("echilibru.in", "r", stdin);
	freopen("echilibru.out", "w", stdout);
	
	read();
	init();
	solve();
	
	return 0;
}