n, k = gets.split.map(&:to_i)
pp = gets.split.map{|e| e = e.to_i; [e, e, true]}

class SegTree
    def update(k); @d[k] = @op.call(@d[2 * k], @d[2 * k + 1]); end

    def initialize(v, e, &op)
        @n = v.size
        @log = (@n - 1).bit_length
        @size = 1 << @log
        @op = op

        @d = Array.new(2 * @size, e) # vector

        @n.times{|i| @d[@size + i] = v[i]}
        (@size - 1).downto(1) {|i| update(i)}
    end

    def set(pos, x)
        pos += @size
        @d[pos] = x
        1.upto(@log) {|i| update(pos >> i)}
    end

    def get(pos); @d[pos + @size]; end

    def prod(l, r)
        sml = smr = @d[0]
        l += @size
        r += @size

        while l < r
            (sml = @op.call(sml, @d[l]); l += 1) if l[0] == 1
            (r -= 1; smr = @op.call(@d[r], smr)) if r[0] == 1
            l >>= 1
            r >>= 1
        end
        @op.call(sml, smr)
    end

    def all_prod; @d[1]; end
end

st = SegTree.new(pp, -1) do |c1, c2|
    if c1 == -1
        c2
    elsif c2 == -1
        c1
    elsif c1[2] && c2[2] && c1[1] < c2[0]
        [c1[0], c2[1], true]
    else
        [[c1[0], c2[0]].min, [c1[1], c2[1]].max, false]
    end
end

ans = 1
f = st.prod(0, k)[2]
(n - k).times do |i|
    a = st.prod(i, i+k)
    b = st.prod(i+1, i+k+1)
    next if a[0] == pp[i][0] && b[1] == pp[i+k][0]
    next if f && b[2]
    f |= b[2]
    ans += 1
end
p ans