n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
inv = [0]
group = [0]
1.upto(n - 1) do |i|
    if p[i - 1] > p[i] then
        inv[i] = inv[i - 1] + 1
        group[i] = i
    else
        inv[i] = inv[i - 1]
        group[i] = group[i - 1]
    end
end

count = 0
exist_id = false
if inv[0] == inv[k - 1] then
    exist_id = true
else
    count = 1
end
1.upto(n - k) do |i|
    if inv[i] == inv[i + k - 1] then
        exist_id = true
    else
        if p[(i - 1)..(i + k - 2)].min != p[i - 1] || p[i..(i + k - 1)].max != p[i + k - 1] then
            count += 1
        end
    end
end

if exist_id then
    puts count + 1
else
    puts count
end
