def getmax(a,s,e)
	s=[s,0].min
	ma=a[s]
	(s..e).each{|i| ma=a[i] if a[i]>ma}
	ma
end

def getmin(a,s,e)
	s=[s,0].min
	mi=a[s]
	(s..e).each{|i| mi=a[i] if a[i]<mi}
	mi
end

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]
 
	ma=getmax(a,i-k,i)
	mi=getmin(a,i-k,i)
 
	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)