import scala.io.StdIn._

object Main extends App {

  val Array(n,k) = readLine().split(" ").map(_.toInt)
  val h = readLine().split(" ").map(_.toInt)
  def solve() = {
    val dp = Array.fill(n)(Int.MaxValue)
    for(i <- 0 until n) {
      if(i == 0) dp(i) = 0
      else {
        val start = Math.max(0, i-k)
        for(j <- start until i) {
          dp(i) = Math.min(dp(i), dp(j) + (h(i) - h(j)).abs)
        }
      }
    }
    dp(n-1)
  }

  println(solve())

}

