INF = 10**8
N, K = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)

dp = Array.new(N, INF)
dp[0] = 0
N.times do |i|
  1.upto(K) do |k|
    if i + k <= N - 1
      dp[i + k] = [dp[i + k], dp[i] + (arr[i] - arr[i + k]).abs].min
    end
  end
end
p dp[N-1]