n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
INF = 1001001001
dp = Array.new(n, INF)
dp[0] = 0
(n-1).times{|i|
  i+=1
  min = INF
  k.times{|j|
    j+=1
    min = [dp[i-j]+(h[i]-h[i-j]).abs, min].min if i>(j-1)
  }
  dp[i] = min
}
p dp[n-1]

