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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int k = stdIn.nextInt();
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]- h[0]);
		
		for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[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) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int k = stdIn.nextInt();
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]- h[0]);
		
		for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		}
		System.out.println(dp[n-1]);
		
		
	}

} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int k = stdIn.nextInt();
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]- h[0]);
		
		for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		}
		System.out.println(dp[n-1]);
		
		
	} main {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int k = stdIn.nextInt();
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]- h[0]);
		
		for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		}
		System.out.println(dp[n-1]);
		
		
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int k = stdIn.nextInt(); k stdIn.nextInt() stdIn.nextInt stdIn int[] h = new int[n]; h new int[n] n for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = stdIn.nextInt();
		} {
			h[i] = stdIn.nextInt();
		} h[i] = stdIn.nextInt() h[i] h i stdIn.nextInt() stdIn.nextInt stdIn 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 dp[1] = Math.abs(h[1]- h[0]) dp[1] dp 1 Math.abs(h[1]- h[0]) Math.abs Math h[1]- h[0] h[1] h 1 h[0] h 0 for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		} {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		} for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			} int j = i+1; int j = i+1; j i+1 i 1 j <= i+k j i+k i k j++ j++ j {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			} {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			} if(j >= n) {
					break;
				} j >= n j n {
					break;
				} break; dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]) dp[j] dp j Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]) Math.min Math dp[i]+Math.abs(h[j]-h[i]) dp[i] dp i Math.abs(h[j]-h[i]) Math.abs Math h[j]-h[i] h[j] h j h[i] h i dp[j] dp 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) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int k = stdIn.nextInt();
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]- h[0]);
		
		for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		}
		System.out.println(dp[n-1]);
		
		
	}

} public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int k = stdIn.nextInt();
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]- h[0]);
		
		for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[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) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //足場の数
		
		int k = stdIn.nextInt();
		
		int[] h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		dp[1] = Math.abs(h[1]- h[0]);
		
		for(int i = 0; i < n; i++ ) {
			
			for(int j = i+1; j <= i+k; j++) {
				if(j >= n) {
					break;
				}
				dp[j] = Math.min(dp[i]+Math.abs(h[j]-h[i]),dp[j]);
						
				
			}
			
			
			
		}
		System.out.println(dp[n-1]);
		
		
	}

}
