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=a[[i-k,0].max,a[i]].min
	ma=a[[i-k,0].max,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>0?y-1:0)