

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		}

		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) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		}

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

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		}

		System.out.println(dp[n - 1]);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		}

		System.out.println(dp[n - 1]);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int input[] = new int[n]; input new int[n] n for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			input[i] = sc.nextInt();
		} {
			input[i] = sc.nextInt();
		} input[i] = sc.nextInt() input[i] input i sc.nextInt() sc.nextInt sc 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 = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		} {
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		} for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			} int j = 1; int j = 1; j 1 j <= k && i - j >= 0 j <= k j k i - j >= 0 i - j i j 0 j++ j++ j {
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			} {
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			} dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j])) dp[i] dp i Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j])) Math.min Math dp[i] dp i dp[i - j] + Math.abs(input[i] - input[i - j]) dp[i - j] dp i - j i j Math.abs(input[i] - input[i - j]) Math.abs Math input[i] - input[i - j] input[i] input i input[i - j] input i - j i j 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) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		}

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

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		}

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

} Main


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int input[] = new int[n];
		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		int dp[] = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for(int i = 1; i < n; i++){
			for(int j = 1; j <= k && i - j >= 0; j++){
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
			}
		}

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

}

