import java.util.Scanner

import scala.math._

object Main extends App {
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt
  val h = Array.fill(N)(sc.nextInt)

  val dp = Array.fill(N)(Int.MaxValue)

  dp(0) = 0
  for (i <- 1 until N) {
    val dps = (1 to K).map(x => if (x <= i) dp(i - x) + abs(h(i) - h(i - x)) else Int.MaxValue)
    dp(i) = dps.min
  }
  println(dp.last)
}
