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

s = P[0,K].sort
n, pm = s == P[0,K] ? [0, 1] : [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 <=> _ })
	if s == P[i+1,K]
		pm += 1
	elsif min != pop or push != s[-1]
		n += 1
	end
}

p n+[pm,1].min
