N , K = gets.split.map{|i| i.to_i}
h = gets.split.map{|i| i.to_i}
dp = Array.new(N , 10 ** 19)
dp [0] = 0

for i in 0 .. N - 2
    for j in 1 .. K
        if i + j > N - 1
            break
        end

        if (dp[i + j] > dp[i] + (h[i] - h[i + j]).abs)
            dp[i + j] = dp[i] + (h[i] - h[i + j]).abs
        end
    end
end

puts dp[N - 1]