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

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

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