/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
5 3
10 30 40 50 20
---+/
/+---test
3 1
10 20 10
---+/
/+---test
2 100
10 10
---+/

void main(string[] args) {
  int N, K;
  readf(" %d %d ", &N, &K);

  const heights = readln.split.map!(to!long).array;

  auto dp = new long[N];
  dp[]  = long.max;
  dp[0] = 0;

  foreach (i; 0..N-1) {
    foreach (k; 0..min(K, i+1)) {
      dp[i+1] = dp[i+1].min(dp[i-k] + abs(heights[i-k] - heights[i+1]));
    }
  }
  dp[$-1].writeln;
}
