N, K = gets.split(' ').take(2).map(&:to_i)
height_list = gets.split(' ').take(N).map(&:to_i)

MAX_VALUE = (10 ** 4) * (10 ** 5) + 1
dp = Array.new(N) { MAX_VALUE }
dp[0] = 0

(0...(N - 1)).each do |i|
  height = height_list[i]
  k = [N - 1 - i, K].min
  (1..k).each do |j|
    dp[i + j] = [
      dp[i + j],
      dp[i] + (height - height_list[i + j]).abs
    ].min
  end
end

puts dp[N - 1]
