import java.util.*;
import java.io.*;
class Main
{
  public static void main (String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] s = br.readLine().split("\\s");
    	int n = Integer.parseInt(s[0]);
    	int k = Integer.parseInt(s[1]);
		String[] ss = br.readLine().split("\\s");
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        {
          arr[i] = Integer.parseInt(ss[i]);
      	}
      	int t1=0;
      	if(n == 1)
      	{
      		System.out.println(t1);
      		return;
      	}
      	int[] dp = new int[n];
      	Arrays.fill(dp, Integer.MAX_VALUE);
      	dp[0] = 0;
      	for(int i = 0; i < n; i++)
      	{
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	}
      	System.out.println(dp[n-1]);
    }
} import java.util.*; util.* java import java.io.*; io.* java class Main
{
  public static void main (String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] s = br.readLine().split("\\s");
    	int n = Integer.parseInt(s[0]);
    	int k = Integer.parseInt(s[1]);
		String[] ss = br.readLine().split("\\s");
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        {
          arr[i] = Integer.parseInt(ss[i]);
      	}
      	int t1=0;
      	if(n == 1)
      	{
      		System.out.println(t1);
      		return;
      	}
      	int[] dp = new int[n];
      	Arrays.fill(dp, Integer.MAX_VALUE);
      	dp[0] = 0;
      	for(int i = 0; i < n; i++)
      	{
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	}
      	System.out.println(dp[n-1]);
    }
} Main public static void main (String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] s = br.readLine().split("\\s");
    	int n = Integer.parseInt(s[0]);
    	int k = Integer.parseInt(s[1]);
		String[] ss = br.readLine().split("\\s");
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        {
          arr[i] = Integer.parseInt(ss[i]);
      	}
      	int t1=0;
      	if(n == 1)
      	{
      		System.out.println(t1);
      		return;
      	}
      	int[] dp = new int[n];
      	Arrays.fill(dp, Integer.MAX_VALUE);
      	dp[0] = 0;
      	for(int i = 0; i < n; i++)
      	{
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	}
      	System.out.println(dp[n-1]);
    } main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] s = br.readLine().split("\\s");
    	int n = Integer.parseInt(s[0]);
    	int k = Integer.parseInt(s[1]);
		String[] ss = br.readLine().split("\\s");
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        {
          arr[i] = Integer.parseInt(ss[i]);
      	}
      	int t1=0;
      	if(n == 1)
      	{
      		System.out.println(t1);
      		return;
      	}
      	int[] dp = new int[n];
      	Arrays.fill(dp, Integer.MAX_VALUE);
      	dp[0] = 0;
      	for(int i = 0; i < n; i++)
      	{
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	}
      	System.out.println(dp[n-1]);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] s = br.readLine().split("\\s"); s br.readLine().split("\\s") br.readLine().split br.readLine() br.readLine br "\\s" int n = Integer.parseInt(s[0]); n Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 int k = Integer.parseInt(s[1]); k Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 String[] ss = br.readLine().split("\\s"); ss br.readLine().split("\\s") br.readLine().split br.readLine() br.readLine br "\\s" int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i++)
        {
          arr[i] = Integer.parseInt(ss[i]);
      	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
          arr[i] = Integer.parseInt(ss[i]);
      	} {
          arr[i] = Integer.parseInt(ss[i]);
      	} arr[i] = Integer.parseInt(ss[i]) arr[i] arr i Integer.parseInt(ss[i]) Integer.parseInt Integer ss[i] ss i int t1=0; t1 0 if(n == 1)
      	{
      		System.out.println(t1);
      		return;
      	} n == 1 n 1 {
      		System.out.println(t1);
      		return;
      	} System.out.println(t1) System.out.println System.out System System.out t1 return; int[] dp = new int[n]; dp new int[n] n Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0] = 0 dp[0] dp 0 0 for(int i = 0; i < n; i++)
      	{
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	} {
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	} for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		} int j = i+1; int j = i+1; j i+1 i 1 j <= Math.min(k+i, n-1) j Math.min(k+i, n-1) Math.min Math k+i k i n-1 n 1 j++ j++ j {
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		} {
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		} dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i])) dp[j] dp j Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i])) Math.min Math dp[j] dp j dp[i] + Math.abs(arr[j]-arr[i]) dp[i] dp i Math.abs(arr[j]-arr[i]) Math.abs Math arr[j]-arr[i] arr[j] arr j arr[i] arr i System.out.println(dp[n-1]) System.out.println System.out System System.out dp[n-1] dp n-1 n 1 String[] args args
import java.util.*;
import java.io.*;
class Main
{
  public static void main (String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] s = br.readLine().split("\\s");
    	int n = Integer.parseInt(s[0]);
    	int k = Integer.parseInt(s[1]);
		String[] ss = br.readLine().split("\\s");
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        {
          arr[i] = Integer.parseInt(ss[i]);
      	}
      	int t1=0;
      	if(n == 1)
      	{
      		System.out.println(t1);
      		return;
      	}
      	int[] dp = new int[n];
      	Arrays.fill(dp, Integer.MAX_VALUE);
      	dp[0] = 0;
      	for(int i = 0; i < n; i++)
      	{
      		for(int j = i+1; j <= Math.min(k+i, n-1); j++)
      		{
      			dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j]-arr[i]));
      		}
      	}
      	System.out.println(dp[n-1]);
    }
}