
import java.util.*;

public class Main {

	public static void main(String args[]) {

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	}

	public static int frog(int[] arr, int k,int n) {
		int dp[] = new int[n + 1];
		
		for (int i = 2; i <=n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			}

		}
		return dp[n];

	}
} import java.util.*; util.* java public class Main {

	public static void main(String args[]) {

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	}

	public static int frog(int[] arr, int k,int n) {
		int dp[] = new int[n + 1];
		
		for (int i = 2; i <=n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			}

		}
		return dp[n];

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

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	} main {

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int n = scn.nextInt(); n scn.nextInt() scn.nextInt scn int k = scn.nextInt(); k scn.nextInt() scn.nextInt scn int arr[] = new int[n+1]; arr new int[n+1] n+1 n 1 for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		} int i = 1; int i = 1; i 1 i <=n i n i++ i++ i {
			arr[i] = scn.nextInt();

		} {
			arr[i] = scn.nextInt();

		} arr[i] = scn.nextInt() arr[i] arr i scn.nextInt() scn.nextInt scn System.out.println(frog(arr, k,n)) System.out.println System.out System System.out frog(arr, k,n) frog arr k n String args[] args public static int frog(int[] arr, int k,int n) {
		int dp[] = new int[n + 1];
		
		for (int i = 2; i <=n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			}

		}
		return dp[n];

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

		}
		return dp[n];

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

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

		} {
			dp[i] = Integer.MAX_VALUE;
			for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			}

		} dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			} int j = i - 1; int j = i - 1; j i - 1 i 1 j >= 1 && (i - j) <= k j >= 1 j 1 (i - j) <= k (i - j) i j k j-- j-- j {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			} {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			} dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]) dp[i] dp i Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]) Math.min Math dp[i] dp i Math.abs(arr[i] - arr[j]) + dp[j] Math.abs(arr[i] - arr[j]) Math.abs Math arr[i] - arr[j] arr[i] arr i arr[j] arr j dp[j] dp j return dp[n]; dp[n] dp n int[] arr arr int k k int n n public class Main {

	public static void main(String args[]) {

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	}

	public static int frog(int[] arr, int k,int n) {
		int dp[] = new int[n + 1];
		
		for (int i = 2; i <=n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			}

		}
		return dp[n];

	}
} public class Main {

	public static void main(String args[]) {

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	}

	public static int frog(int[] arr, int k,int n) {
		int dp[] = new int[n + 1];
		
		for (int i = 2; i <=n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			}

		}
		return dp[n];

	}
} Main

import java.util.*;

public class Main {

	public static void main(String args[]) {

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	}

	public static int frog(int[] arr, int k,int n) {
		int dp[] = new int[n + 1];
		
		for (int i = 2; i <=n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j = i - 1; j >= 1 && (i - j) <= k; j--) {
				dp[i] = Math.min(dp[i], Math.abs(arr[i] - arr[j]) + dp[j]);
			}

		}
		return dp[n];

	}
}