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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scn = new Scanner(System.in);
		int[]a=new int[scn.nextInt()];
		int k=scn.nextInt();
		for(int i=0;i<a.length;i++)a[i]=scn.nextInt();
		System.out.println(solve(a, k));
		
	}
	
	public static int solve(int[]a, int k) {
		int[]dp=new int[a.length];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0]=0;
		for(int i=1;i<a.length;i++) {
			for(int j=1;j<=k;j++) {
				dp[i]=Math.min(dp[i], i-j>=0?(dp[i-j]+Math.abs(a[i]-a[i-j])):Integer.MAX_VALUE);
			}
		}
		return dp[dp.length-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 scn = new Scanner(System.in);
		int[]a=new int[scn.nextInt()];
		int k=scn.nextInt();
		for(int i=0;i<a.length;i++)a[i]=scn.nextInt();
		System.out.println(solve(a, k));
		
	}
	
	public static int solve(int[]a, int k) {
		int[]dp=new int[a.length];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0]=0;
		for(int i=1;i<a.length;i++) {
			for(int j=1;j<=k;j++) {
				dp[i]=Math.min(dp[i], i-j>=0?(dp[i-j]+Math.abs(a[i]-a[i-j])):Integer.MAX_VALUE);
			}
		}
		return dp[dp.length-1];
	}
	

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scn = new Scanner(System.in);
		int[]a=new int[scn.nextInt()];
		int k=scn.nextInt();
		for(int i=0;i<a.length;i++)a[i]=scn.nextInt();
		System.out.println(solve(a, k));
		
	}
	
	public static int solve(int[]a, int k) {
		int[]dp=new int[a.length];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0]=0;
		for(int i=1;i<a.length;i++) {
			for(int j=1;j<=k;j++) {
				dp[i]=Math.min(dp[i], i-j>=0?(dp[i-j]+Math.abs(a[i]-a[i-j])):Integer.MAX_VALUE);
			}
		}
		return dp[dp.length-1];
	}
	

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scn = new Scanner(System.in);
		int[]a=new int[scn.nextInt()];
		int k=scn.nextInt();
		for(int i=0;i<a.length;i++)a[i]=scn.nextInt();
		System.out.println(solve(a, k));
		
	}
	
	public static int solve(int[]a, int k) {
		int[]dp=new int[a.length];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0]=0;
		for(int i=1;i<a.length;i++) {
			for(int j=1;j<=k;j++) {
				dp[i]=Math.min(dp[i], i-j>=0?(dp[i-j]+Math.abs(a[i]-a[i-j])):Integer.MAX_VALUE);
			}
		}
		return dp[dp.length-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 scn = new Scanner(System.in);
		int[]a=new int[scn.nextInt()];
		int k=scn.nextInt();
		for(int i=0;i<a.length;i++)a[i]=scn.nextInt();
		System.out.println(solve(a, k));
		
	}
	
	public static int solve(int[]a, int k) {
		int[]dp=new int[a.length];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0]=0;
		for(int i=1;i<a.length;i++) {
			for(int j=1;j<=k;j++) {
				dp[i]=Math.min(dp[i], i-j>=0?(dp[i-j]+Math.abs(a[i]-a[i-j])):Integer.MAX_VALUE);
			}
		}
		return dp[dp.length-1];
	}
	

}
