import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		String[] temp2 = scanner.nextLine().split(" ");
		int[] 	 list  = new int[n];

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		}


		int[] dp = new int[n+1];

		Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        }

        System.out.println(dp[n - 1]);


	}

} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		String[] temp2 = scanner.nextLine().split(" ");
		int[] 	 list  = new int[n];

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		}


		int[] dp = new int[n+1];

		Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        }

        System.out.println(dp[n - 1]);


	}

} Main public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		String[] temp2 = scanner.nextLine().split(" ");
		int[] 	 list  = new int[n];

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		}


		int[] dp = new int[n+1];

		Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        }

        System.out.println(dp[n - 1]);


	} main {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		String[] temp2 = scanner.nextLine().split(" ");
		int[] 	 list  = new int[n];

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		}


		int[] dp = new int[n+1];

		Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        }

        System.out.println(dp[n - 1]);


	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] temp = scanner.nextLine().split(" "); temp scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int n = Integer.parseInt(temp[0]); n Integer.parseInt(temp[0]) Integer.parseInt Integer temp[0] temp 0 int k = Integer.parseInt(temp[1]); k Integer.parseInt(temp[1]) Integer.parseInt Integer temp[1] temp 1 String[] temp2 = scanner.nextLine().split(" "); temp2 scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int[] 	 list  = new int[n]; list new int[n] n for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			list[i] = Integer.parseInt(temp2[i]);
		} {
			list[i] = Integer.parseInt(temp2[i]);
		} list[i] = Integer.parseInt(temp2[i]) list[i] list i Integer.parseInt(temp2[i]) Integer.parseInt Integer temp2[i] temp2 i int[] dp = new int[n+1]; dp new int[n+1] n+1 n 1 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 < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        } {
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        } for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n && j <= i + k j < n j n j <= i + k j i + k i k j++ j++ j {
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            } {
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            } dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i])) dp[j] dp j Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i])) Math.min Math dp[j] dp j dp[i] + Math.abs(list[j] - list[i]) dp[i] dp i Math.abs(list[j] - list[i]) Math.abs Math list[j] - list[i] list[j] list j list[i] list 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 public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		String[] temp2 = scanner.nextLine().split(" ");
		int[] 	 list  = new int[n];

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		}


		int[] dp = new int[n+1];

		Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        }

        System.out.println(dp[n - 1]);


	}

} public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		String[] temp2 = scanner.nextLine().split(" ");
		int[] 	 list  = new int[n];

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		}


		int[] dp = new int[n+1];

		Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        }

        System.out.println(dp[n - 1]);


	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int k = Integer.parseInt(temp[1]);

		String[] temp2 = scanner.nextLine().split(" ");
		int[] 	 list  = new int[n];

		for(int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(temp2[i]);
		}


		int[] dp = new int[n+1];

		Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n && j <= i + k; j++){
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(list[j] - list[i]));
            }
        }

        System.out.println(dp[n - 1]);


	}

}
