object Main{
  def main(args: Array[String]) : Unit = {
    System.err.println("ok")
    val sc = new java.util.Scanner(System.in)
    val n,k = sc.nextInt
    val h : Array[Int] = 0 +: (1 to n).toArray.map{_ => sc.nextInt } 

    val dp = new Array[Int](n + 1)
    dp(n) = 0
    dp(n-1) = (h(n-1) - h(n)).abs
    (n-2 to 1 by -1).foreach{ x => 
      dp(x) = (1 to k).map { jump =>
        if(x + jump > n) {
          10000000
        } else {
          (h(x) - h(x + jump)).abs + dp(x+jump)
        }
      }.min
    }
    println(dp(1))
  }
}

