import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);


void main() {
    int n, k;
    readf("%d %d\n", &n, &k);
    int[] h = reads();

    int[] dp = new int[n];
    dp[] = 1 << 29;
    dp[0] = 0;
    foreach (i; 1..n) {
        foreach (j; 1 .. k+1) {
            int dst = i - j;
            if (dst < 0) break;
            dp[i] = min(dp[i],
                    abs(h[i] - h[dst]) + dp[dst]);
        }
    }
    writeln(dp[n - 1]);
}
