n,k,*a=gets(p).split.map &:to_i
pr=-1
b,x,y,mi,ma=[0]*5
(0..n-1).each{|i|
	a[i] > pr ? b+=1 : b=1
	pr=a[i]

	mi = [mi,a[i]].min
	ma = [ma,a[i]].max

	x += 1 if i>=k and mi==a[i-k] and ma==a[i]
	y += 1 if b >= k
}

p n-(k-1)-x-(y>1?y-1:0)