import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!long).array;

    auto dp = new long[](N);
    fill(dp, 1L << 59);
    dp[0] = 0;

    foreach (i; 1..N) {
        foreach (j; max(0, i - K)..i) {
            dp[i] = min(dp[i], dp[j] + abs(A[i] - A[j]));
        }
    }

    dp[N-1].writeln;
}
