import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Data.Char

solve :: VU.Vector Int -> Int -> Int -> Int
solve hs n k =
  runST $ do
    dp <- VUM.replicate (n+1) (10^5)
    VUM.write dp 0 0
    forM_ [1..n-1] $ \now -> do
      xs <- forM [now-k,now-k+1..now-1] $ \prev ->
              if prev >= 0 then do
                n <- VUM.read dp prev
                let diff = abs $ (hs VU.! now) - (hs VU.! prev) 
                return $ n + diff
              else
                return $ 10^9
      let x = minimum xs 
      VUM.write dp now x          
    VUM.read dp (n-1)


main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  hs <- VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve hs n k 
