import Data.Array

main = do
    [n,k] <- map read.words <$> getLine :: IO [Int]
    hs <- listArray (1,n) . map read.words <$> getLine
    print $ answer n k hs

answer n k hs = dp ! 1 where
    dp = array (1,n) $ (n,0): (n-1, n#(n-1)):[ (now, move now) | now <- [1..n-2]]
    move now = minimum $ map (\i -> (dp!(now+i) + now#(now+i))) [1..min k (n-now)]
    a # b = abs $ (hs!a) - (hs!b)