import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V

a#b = abs$a-b

main = do
    [n,k] <- map read.words<$>getLine
    hr <- V.unfoldr(B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ f n k hr

f n k h=dp V.! (n-1) where
    dp = V.generate n m
    m 0 = 0
    m i = V.minimum $ V.zipWith (+) (V.slice s l dp) $ V.map (# (h V.! i)) $ V.slice s l h
        where
            s = max 0 (i-k)
            l = i-s