let [|N;K|] = stdin.ReadLine().Split() |> Array.map int
let p = stdin.ReadLine().Split() |> Array.map int
let A = N-K+1
let rec f i a =
    if i>=N-K-1 then a
    else
        let b = p.[i..(i+K)]
        if (b.[0]=(Array.min b)) && (b.[K]=(Array.max b)) then f (i+1) (a-1)
        else f (i+1) a
let rec g i q a =
    if i>=N-K then a
     else
        let b = p.[i..(i+K-1)]
        if (b=(Array.sort b)) && (q=1) then g (i+1) q (a-1)
        elif (b=(Array.sort b)) && (q=0) then g (i+1) 1 (a-1)
        else g (i+1) q a
f 0 A |> g 0 0 |> stdout.WriteLine