import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);
	auto K = to!ulong(tokens[1]);

	long[] h;
	foreach (token; split(my_readln()))
	{
		h ~= to!long(token);
	}

	ulong[] costs;
	costs.length = N;
	fill(costs, ulong.max);
	costs[0] = 0;
	foreach (i; 0..N)
	{
		foreach (j; 1..K+1)
		{
			if (i + j >= N) break;
			costs[i+j] = min(costs[i+j], costs[i] + abs(h[i] - h[i+j]));
		}
	}

	writeln(costs[N-1]);
	stdout.flush();
	/*}catch (Throwable e)
	{
	writeln(e.toString());
	}
	readln();*/
}