
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		}
		System.out.println(dp[n-1]);
	}
	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.PrintWriter; PrintWriter java.io import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		}
		System.out.println(dp[n-1]);
	}
	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		}
		System.out.println(dp[n-1]);
	} main {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		}
		System.out.println(dp[n-1]);
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int k =sc.nextInt(); k sc.nextInt() sc.nextInt sc long[]a = input(n); a input(n) input n long[] dp = new long[n]; dp new long[n] n for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		} int i =1 ; int i =1 ; i 1 i < n i n i++ i++ i {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		} {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		} long max = Integer.MAX_VALUE ; max Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			} 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 {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			} {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			} long temp = Math.abs(a[i]-a[i-j]) + dp[i-j]; temp Math.abs(a[i]-a[i-j]) + dp[i-j] Math.abs(a[i]-a[i-j]) Math.abs Math a[i]-a[i-j] a[i] a i a[i-j] a i-j i j dp[i-j] dp i-j i j max = Math.min(temp, max) max Math.min(temp, max) Math.min Math temp max dp[i]=max dp[i] dp i max 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 static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	} input {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	} long[] arr = new long[n]; arr new long[n] n for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = sc.nextLong();
		} {
			arr[i] = sc.nextLong();
		} arr[i] = sc.nextLong() arr[i] arr i sc.nextLong() sc.nextLong sc return arr; arr int n n public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		}
		System.out.println(dp[n-1]);
	}
	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

} public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		}
		System.out.println(dp[n-1]);
	}
	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

} Main

import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long max = Integer.MAX_VALUE ;
			for(int j =1  ; j<=k && i-j>=0;j++ ) {
				long temp = Math.abs(a[i]-a[i-j]) + dp[i-j];
				max = Math.min(temp, max);
			}
			dp[i]=max  ;
		}
		System.out.println(dp[n-1]);
	}
	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

}
