open Batteries
let n, k = Scanf.sscanf (read_line()) "%d %d" (fun n k -> n, k)
let h = Array.init n (fun a -> Scanf.scanf " %d" @@ fun b -> b)

let dp = Array.init 100010 @@ fun a -> max_int
let _ = dp.(0) <- 0

let change i w =
  if dp.(i) > dp.(i-w) + (abs @@ h.(i) - h.(i-w)) then dp.(i) <- dp.(i-w) + (abs @@ h.(i) - h.(i-w))


let rec loop i =
  if i >= n then dp.(n-1) else (
    change i 1; 
    if i > 1 then 
    let rec loop2 i2 =
      if i2 > k || -1 >= (i - i2) then () else (change i i2; loop2 (i2+1))
    in loop2 2
     else ();
    loop (i+1)
    )


let _ = Printf.printf "%d\n" @@ loop 1
