import Data.Array

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

answer n k hs = dp ! 1 where
    table = listArray ((1,1), (n,n)) [ (x#y) | x <- [1..n], y <- [1..n] ]
    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) + table!(now, now+i))) [1..min k (n-now)]
    a # b = if b <= a+k && a < b then abs (hs!a - hs!b) else 0