function updMin(dp, i, j, dif) {
    //console.log(`dp[i]=${dp[i]}, dp[j]=${dp[j]}`)
    if(dp[i] > dp[j]+dif) {
        dp[i] = dp[j]+dif
    }
}

function main(arg) {
    const [N,K] = arg.split("\n")[0].split(" ").map(x=>Number(x))
    const h = arg.split("\n")[1].split(" ").map(x=>Number(x))

    let dp = [...Array(N)].map(x=>Math.pow(10,4)+1)
    dp[0] = 0
    
    for(let n = 1; n < N; n++) {
        for(let k = 1; k <= K; k++) {
            if(n-k >= 0) {
                updMin(dp, n, n-k, Math.abs(h[n] - h[n-k]))
            }
        }    
    }
    console.log(dp[N-1])
}

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