INF = 1 << 60

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

# minimize
dp = Array.new(n, INF)
# init
dp[0] = 0
# change min
n.times do |i|
  (1..k).each do |d|
    j = i + d
    next unless j < n
    a = dp[j]
    b = dp[i] + (hs[i] - hs[j]).abs
    dp[j] = a <= b ? a : b
  end
end

p dp.last
