local mmi, mma = math.min, math.max
local mab = math.abs
local n, k = io.read("*n", "*n")
local h = {}
local cost = {}
for i = 1, n do
  h[i] = io.read("*n")
  cost[i] = 1000000007 * 100
end
cost[1] = 0
for i = 1, n - 1 do
  local lim = mmi(k, n - i)
  for j = 1, lim do
    cost[i + j] = mmi(cost[i + j], cost[i] + mab(h[i + j] - h[i]))
  end
end
print(cost[n])
