n,k=gets.split.map(&:to_i)
h=Array.new(n+k,0)
h=gets.split.map(&:to_i)
k.times do
    h<<0
end

dp=Array.new(n+k,10**10)
dp[0]=0
n.times do |i|
    1.upto(k) do |j|
        dp[i+j]=[dp[i]+(h[i+j]-h[i]).abs,dp[i+j]].min
    end
end
puts dp[n-1]
