N,K=gets.chomp.split(" ").map(&:to_i)
array = gets.chomp.split(" ").map(&:to_i)

ret = 0
sorted_added = false
pre_min = nil
pre_max = nil
(0..N-K).each_with_index do |e, i|
    if i > 0 && pre_min == array[i-1] && pre_max <= array[i+K-1]
        next
    end
    sub = array.slice(i..(i+K-1))
    if sub.each_cons(2).all? {|a, b| a <= b }
        if sorted_added
            next
        else
            sorted_added = true
        end
    end
    sub_sorted = sub.sort
    pre_min = sub_sorted[0]
    pre_max = sub_sorted[-1]
    ret += 1
end
puts ret
