import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toInt()}

    if (N == K) {
        println(1)
        return
    }

    val P = readLine()!!.split(" ").map{it.toInt()}
    val cnt = IntArray(N) { 0 }

    cnt[0] = 1

    for (i in 1 until N) {
        if (P[i - 1] < P[i]) {
            cnt[i] = cnt[i - 1] + 1
        } else {
            cnt[i] = 1
        }
    }

    val sorted = cnt.count { it >= K }

    var res = if (cnt[K - 1] >= K) 0 else 1

    val st = TreeSet<Int>()

    for (i in 0 until K) {
        st.add(P[i])
    }

    for (i in K until N) {
        st.add(P[i])
        var f = false

        if (st.first() != P[i - K] || st.last() != P[i]) {
            res++
            f = true
        }

        st.remove(P[i - K])

        if (f && cnt[i] >= K && sorted >= 2) {
            res--
        }
    }
    if (sorted >= 2) {
        res++
    }

    println(res)
}
