let kInf = 1 lsl 60
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let hs = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let dp = Array.make n kInf
let _ =
  dp.(0) <- 0;
  for i = 1 to n - 1 do
    for j = 1 to k do
      if i >= j then dp.(i) <- min dp.(i) @@ dp.(i - j) + abs (hs.(i) - hs.(i - j)) done done;
  Printf.printf "%d\n" dp.(n - 1)