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

inf = 10^18
f n k h=dp V.! (n-1) where
    dp = V.constructN n m
    m v0 | j==0 = 0
         | j<=k = V.foldl' (\a (s,sv)->min a (sv+(h V.! j)#s)) inf $ V.zip h $ V.slice 0 j v0
         | otherwise = V.foldl' (\a (s,sv)->min a (sv+(h V.! j)#s)) inf $ V.zip (V.slice (j-k) k h) $ V.slice (j-k) k v0
        where j = V.length v0
