n, k = gets.split.map(&:to_i)
hs = gets.split.map(&:to_i)

costs = Array.new(n, 10 ** 5)
costs[0] = 0
(1..n-1).each do |i|
  to = [k, i].min
  (1..to).each do |j|
    costs[i] = [costs[i], costs[i-j] + (hs[i] - hs[i-j]).abs].min
  end
end
puts costs[n-1]
