import Prelude hiding ((!))
import Data.Array

main = do
	[n,k] <- map read.words <$> getLine
	xs <- map read.words <$> getLine
	putStrLn.show.answer n k $ xs

answer n k xs = dp ! 0 where
	dp = listArray (0,n-1) $ map jump [0..]
	table = listArray (0,n-1) xs -- convet to array
	jump pos
		| pos == n-1 = 0 -- stand at end pole
		| pos == n-2 = abs (table!pos - table!(pos+1))
		| otherwise = minimum ( map d [1 .. min k (n-1-pos)]) where
			d i = dp ! (pos+i) + move table pos i

move table pos i = abs $ table!pos - table!(pos+i)