#!/usr/bin/env ruby

INF=1<<100

if $0 == __FILE__
  n, k = gets.split(' ').map &:to_i
  h = gets.split(' ').map &:to_i

  dp = Array.new(n, INF)
  dp[0] = 0

  (1..(n-1)).each do |i|
    dp[i] = INF
    (1..k).each do |kk|
      next if i-kk < 0
      value = dp[i-kk] + (h[i] - h[i-kk]).abs
      dp[i] = value if value < dp[i]
    end
  end

  puts dp[n-1]
end
