import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int arr[] = new int[N+1];
		for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(minIncurredCost(N,K,arr));
	}
	
	public static int minIncurredCost(int N, int k, int[]arr) {
		int dp[] = new int[N+1];
		dp[1] = 0;
		for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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.Scanner; Scanner java.util public class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int arr[] = new int[N+1];
		for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(minIncurredCost(N,K,arr));
	}
	
	public static int minIncurredCost(int N, int k, int[]arr) {
		int dp[] = new int[N+1];
		dp[1] = 0;
		for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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 scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int arr[] = new int[N+1];
		for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(minIncurredCost(N,K,arr));
	} main {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int arr[] = new int[N+1];
		for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(minIncurredCost(N,K,arr));
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int K = scan.nextInt(); K scan.nextInt() scan.nextInt scan int arr[] = new int[N+1]; arr new int[N+1] N+1 N 1 for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		} int i=1; int i=1; i 1 i<=N i N i++ i++ i {
			arr[i] = scan.nextInt();
		} {
			arr[i] = scan.nextInt();
		} arr[i] = scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan System.out.println(minIncurredCost(N,K,arr)) System.out.println System.out System System.out minIncurredCost(N,K,arr) minIncurredCost N K arr String[]args args public static int minIncurredCost(int N, int k, int[]arr) {
		int dp[] = new int[N+1];
		dp[1] = 0;
		for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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];
	} minIncurredCost {
		int dp[] = new int[N+1];
		dp[1] = 0;
		for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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 dp[1] = 0 dp[1] dp 1 0 for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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;
			//faced issue
			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;
			//faced issue
			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 N N int k k int[]arr arr public class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int arr[] = new int[N+1];
		for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(minIncurredCost(N,K,arr));
	}
	
	public static int minIncurredCost(int N, int k, int[]arr) {
		int dp[] = new int[N+1];
		dp[1] = 0;
		for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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 scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int arr[] = new int[N+1];
		for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(minIncurredCost(N,K,arr));
	}
	
	public static int minIncurredCost(int N, int k, int[]arr) {
		int dp[] = new int[N+1];
		dp[1] = 0;
		for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		
		int arr[] = new int[N+1];
		for(int i=1;i<=N;i++) {
			arr[i] = scan.nextInt();
		}
		System.out.println(minIncurredCost(N,K,arr));
	}
	
	public static int minIncurredCost(int N, int k, int[]arr) {
		int dp[] = new int[N+1];
		dp[1] = 0;
		for(int i = 2;i<=N;i++) {
			dp[i] =  Integer.MAX_VALUE;
			//faced issue
			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];
	}
	
	
}