'use strict'

const main = input => {
	const args = input.split('\n').map(t => t.split(' '))
	const n = parseInt(args[0][0], 10)
	const k = parseInt(args[0][1], 10)
	const h = args[1].map(t => parseInt(t, 10))
	const dp = new Array(n + k)

	for (let i = 0; i < dp.length; i++) {
		dp[i] = Infinity
	}

	dp[0] = 0

	for (let i = 0; i < n; i++) {
		for (let j = 1; j <= k; j++) {
			dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]))
		}
	}

	console.log(dp[n - 1])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
