N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i)

n = 1
s = P[0,K].sort
pm = s == P[0,K] ? 1 : 0
(N-K).times {|i|
	min, pop, push = s[0], P[i], P[i+K]
	s.insert(s.bsearch_index{|_| push < _ }||K, push)
	s.delete_at(s.bsearch_index{|_| pop <=> _ })
	n += 1 if min != pop or push != s[-1]
	pm += 1 if s == P[i+1,K]
#p({:s=>s,:min=>min,:pop=>pop,:push=>push,:n=>n,:pm=>pm})
}

p n-[pm-1,0].max
