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

IsPM = lambda{|i|
	return (i...(i+K-1)).all?{|j|
		P[j] < P[j+1]
	}
}
PopIsMin = lambda{|i|
	return P[i+1,K-1].all?{|_| P[i] < _ }
}
PushIsMax = lambda{|i|
	return P[i-K+1,K-1].all?{|_| _ < P[i] }
}

pm, n = IsPM[0] ? [1, 0] : [0, 1]
(N-K).times{|i|
	if IsPM[i+1]
		pm += 1
	elsif ! PopIsMin[i] or ! PushIsMax[i+K]
		n += 1
	end
}

p n+[pm,1].min
