import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as UV

a#b = abs$a-b

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

inf = 10^18
f n k h = UV.last $ UV.foldl' proc (UV.singleton 0) $ UV.tail h where
    proc v0 dh
        | l <= k = UV.snoc v0 $ UV.foldl' m inf $ UV.zip v0 h
        | otherwise = UV.snoc v0 $ UV.foldl' m inf $ UV.zip (UV.tail v0) $ UV.slice (l-k) k h
        where
            l = UV.length v0
            m a (sv,sh) = min a (sv+sh#dh)