import java.util.*;
import java.io.*;

public class Main {
	static int dp[];
	static int k;
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		k=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return (int)(1e5);
		if(i==a.length-1)
			return 0;
		
		
		int op=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		}
		
		
		
		return dp[i]=op;
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
	static int dp[];
	static int k;
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		k=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return (int)(1e5);
		if(i==a.length-1)
			return 0;
		
		
		int op=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		}
		
		
		
		return dp[i]=op;
	}
} Main static int dp[]; dp static int k; k public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		k=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	} main {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		k=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	} Scanner s=new Scanner(System.in); s new Scanner(System.in) int n=s.nextInt(); n s.nextInt() s.nextInt s k=s.nextInt() k s.nextInt() s.nextInt s int a[]=new int[n]; a new int[n] n for(int i=0;i<n;i++)
			a[i]=s.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=s.nextInt(); a[i]=s.nextInt() a[i] a i s.nextInt() s.nextInt s dp=new int[n] dp new int[n] n Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 System.out.println(rec(0,a)) System.out.println System.out System System.out rec(0,a) rec 0 a String[] args args private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return (int)(1e5);
		if(i==a.length-1)
			return 0;
		
		
		int op=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		}
		
		
		
		return dp[i]=op;
	} rec {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return (int)(1e5);
		if(i==a.length-1)
			return 0;
		
		
		int op=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		}
		
		
		
		return dp[i]=op;
	} if(dp[i]!=-1)
			return dp[i]; dp[i]!=-1 dp[i] dp i -1 1 return dp[i]; dp[i] dp i if(i>=a.length)
			return (int)(1e5); i>=a.length i a.length a a.length return (int)(1e5); (int)(1e5) if(i==a.length-1)
			return 0; i==a.length-1 i a.length-1 a.length a a.length 1 return 0; 0 int op=Integer.MAX_VALUE; op Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		} {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		} if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a)); i+j<a.length i+j i j a.length a a.length op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a)) op Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a)) Math.min Math op Math.abs(a[i]-a[i+j])+rec(i+j, a) 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 rec(i+j, a) rec i+j i j a return dp[i]=op; dp[i]=op dp[i] dp i op int i i int[] a a public class Main {
	static int dp[];
	static int k;
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		k=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return (int)(1e5);
		if(i==a.length-1)
			return 0;
		
		
		int op=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		}
		
		
		
		return dp[i]=op;
	}
} public class Main {
	static int dp[];
	static int k;
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		k=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return (int)(1e5);
		if(i==a.length-1)
			return 0;
		
		
		int op=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		}
		
		
		
		return dp[i]=op;
	}
} Main
import java.util.*;
import java.io.*;

public class Main {
	static int dp[];
	static int k;
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		k=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return (int)(1e5);
		if(i==a.length-1)
			return 0;
		
		
		int op=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++) {
			if(i+j<a.length)
				op=Math.min(op,Math.abs(a[i]-a[i+j])+rec(i+j, a));
		}
		
		
		
		return dp[i]=op;
	}
}