#!/usr/bin/env ruby

INF=100000

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] = (1..K).map{|k| i-k < 0 ? INF : dp[i-k] + (H[i] - H[i-k]).abs }.min
  end

  puts dp[N-1]
end
