import std.stdio;
import std.conv;
import std.string;
import std.format;
import std.algorithm;
import std.math;

//string lines = q"[
//abcdeffg]";

long INF = pow(10, 9);
long[] H = [0L];

long cost(int i, int j)
{
    return abs(H[i]-H[j]).to!long;
}

void main()
{
  string lines;
  string buf;

  while (!stdin.eof) {
    buf = stdin.readln();
    lines ~= buf;
  }

  string[] array = splitLines(lines);
    
  int N = array[0].split(" ")[0].to!int;
  int K = array[0].split(" ")[1].to!int;
  array[1].split(" ").each!(a => H ~= a.to!long);
  
  long[] dp = new long[](N+1);
  foreach (ref long e; dp) {
    e = INF;
  }
  dp[1] = 0L;
  
  for (int i = 1; i <= N; i++) {
    for (int j = i+1; j <= i+K; j++) {
      if (j>N) continue;
      dp[j] = min( cost(i, j) + dp[i], dp[j] );
    }
  }
  writeln(dp[N]);
}