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

import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector as V
a#b = abs$a-b

main = B.interact$B.pack.show.g.unfoldr(B.readInt.B.dropWhile isSpace)

g (n:k:hr)=dp V.! (n-1)
    where
        hv = UV.fromListN n hr
        dp = V.generate n $ \i -> if i==0 then 0 else
            let bg = max 0 (i-k)
            in
            UV.minimum $ UV.zipWith (+) (UV.map (# (hv UV.! i)) $ UV.slice bg (i-bg) hv) $ UV.convert $ V.slice bg (i-bg) dp
