let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let h = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let dp = Array.make n max_int in
  dp.(0) <- 0;
  for i = 1 to n-1 do
    for j = 1 to min i k do
      dp.(i) <-
        min dp.(i) (dp.(i-j) + abs (h.(i-j) - h.(i)))
    done
  done;
  Printf.printf "%d\n" dp.(n-1)