import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, k] <- getIntList
    hs <- VU.fromList <$> getIntList
    dp <- VUM.replicate n (10^9)
    VUM.write dp 0 0
    forM_ [0..n-1] $ \i -> do
        forM_ [1..(min k (n - i - 1))] $ \j -> do
            let dk = abs $ (hs VU.! (i + j)) - (hs VU.! i)
            next <- VUM.read dp (i + j)
            now <- VUM.read dp i
            VUM.write dp (i + j) $ min next (now + dk)
    ans <- VUM.read dp (n - 1)
    print ans