def min(a, b)
  a < b ? a : b
end

N, K = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)

dp = Array.new(100105, Float::INFINITY)
dp[0] = 0
(N - 1).times do |i|
  1.upto(min(K, N - 1 - i)) do |j|
    num = dp[i] + (H[i + j] - H[i]).abs
    dp[i + j] = num if num < dp[i + j]
  end
end
puts dp[N - 1]