import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST

a#b = abs$a-b

main = B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:k:hr)=runST $ do
    dp <- newListArray (1,n) (0:repeat maxBound)::ST s (STUArray s Int Int)
    forM_ [(i,j)|i<-[1..n-1], j<-[i+1..min (i+k) n]] $ \(i,j)->do
        c <- (+ (hv ! j)#(hv ! i)) <$> readArray dp i
        writeArray dp j =<< min c <$> readArray dp j
    readArray dp n
    where
        hv = listArray (1,n) hr