# Studying https://atcoder.jp/contests/agc038/submissions/7680063
N, K, *P = $<.read.split.map(&:to_i)

pm, n = 0, 0
i, QMin, QMax = 0, [0], [0]
until (i+=1) == N
	p = P[i]

	min_gone = QMin[0] == i-K
	if p < P[QMin[0]]
		QMin.clear
	else
		QMin.pop while p < P[QMin[-1]]
	end
	QMin << i
	QMin.shift if QMin[0] == i-K

	if P[QMax[0]] < p
		QMax.clear
	else
		QMax.pop while P[QMax[-1]] < p
	end
	QMax << i
	QMax.shift if QMax[0] == i-K
	max_entered = QMax[0] == i

	next if i < K-1

	if QMin.size == K
		pm += 1
	elsif ! min_gone or ! max_entered
		n += 1
	end
end

p n+[pm,1].min
