n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
(k - 1).times { h << 0 }
dp = Array.new(n - 1 + k) { Float::INFINITY }
dp[0] = 0

0.upto(n - 2) do |i|
  (k + 1).times do |j|
    dp[i + j] = [dp[i] + (h[i] - h[i + j]).abs, dp[i + j]].min
  end
end

puts dp[n - 1]
