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

a#b = abs$a-b

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

f n k vh = head $ foldl' p [0] [1..n-1] where
    p l0 i = take (k+1) (x:l0) where
        x = minimum $ map (\(xj,j)-> (vh UV.! j) # (vh UV.! i) + xj) $ zip l0 [i-1,i-2..i-k]
