"use strict";
function Main(input) {
    let lines = input.split("\n");
    let lines1 = lines[0].split(/\s/).map((v) => v - 0);
    let N = lines1[0] - 0;
    let K = lines1[1] - 0;
    let Hs = lines[1].split(/\s/).map((v) => v - 0);

    Hs.unshift(0);
    let dp = new Array(N+K).fill(Number.MAX_SAFE_INTEGER);
    dp[1] = 0;
    for (let n = 0; n <= N; n++) {
        for (let m = 1; m <= K; m++) {
            dp[n + m] = Math.min(dp[n + m], dp[n] + Math.abs(Hs[n + m] - Hs[n]));
        }
    }
    console.log(dp[N]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));