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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 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 Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 1]);
	}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 1]);
	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 1]);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int numStones = sc.nextInt(); numStones sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int[] stoneHeights = new int[numStones]; stoneHeights new int[numStones] numStones for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < numStones i numStones i++ i++ i {
			stoneHeights[i] = sc.nextInt();
		} {
			stoneHeights[i] = sc.nextInt();
		} stoneHeights[i] = sc.nextInt() stoneHeights[i] stoneHeights i sc.nextInt() sc.nextInt sc int[] minCostForStones = new int[numStones]; minCostForStones new int[numStones] numStones Arrays.fill(minCostForStones, Integer.MAX_VALUE) Arrays.fill Arrays minCostForStones Integer.MAX_VALUE Integer Integer.MAX_VALUE minCostForStones[0] = 0 minCostForStones[0] minCostForStones 0 0 for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		} int i = 0; int i = 0; i 0 i < numStones i numStones i++ i++ i {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		} {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		} for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			} int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			} {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			} if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				} (i + j) < numStones (i + j) i j numStones {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				} minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i])) minCostForStones[i + j] minCostForStones i + j i j Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i])) Math.min Math minCostForStones[i + j] minCostForStones i + j i j minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]) minCostForStones[i] minCostForStones i Math.abs(stoneHeights[i + j] - stoneHeights[i]) Math.abs Math stoneHeights[i + j] - stoneHeights[i] stoneHeights[i + j] stoneHeights i + j i j stoneHeights[i] stoneHeights i System.out.println(minCostForStones[numStones - 1]) System.out.println System.out System System.out minCostForStones[numStones - 1] minCostForStones numStones - 1 numStones 1 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 1]);
	}
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 1]);
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int numStones = sc.nextInt();
		int k = sc.nextInt();
		int[] stoneHeights = new int[numStones];
		
		for(int i = 0; i < numStones; i++) {
			stoneHeights[i] = sc.nextInt();
		}
		
		int[] minCostForStones = new int[numStones];
		Arrays.fill(minCostForStones, Integer.MAX_VALUE);
		minCostForStones[0] = 0;
 		for(int i = 0; i < numStones; i++) {
			for(int j = 1; j <= k; j++) {
				if((i + j) < numStones) {
					minCostForStones[i + j] = Math.min(minCostForStones[i + j], minCostForStones[i] + Math.abs(stoneHeights[i + j] - stoneHeights[i]));
				}
			}
		}
		System.out.println(minCostForStones[numStones - 1]);
	}
}