import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nk = readints;
    int n = nk[0], k = nk[1];
    auto a = readints;

    auto dp = new int[a.length];
    for (int i = 1; i < a.length; i++) {
        dp[i] = int.max;
        for (int j = max(0, i - k); j < i; j++) {
            dp[i] = min(dp[i],
                        dp[j] + abs(a[j] - a[i]));
        }
    }
    writeln(dp[$ - 1]);
}
