import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		}
		System.out.println(dp[N-1]);
	}
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java class Main{
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		}
		System.out.println(dp[N-1]);
	}
} Main public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		}
		System.out.println(dp[N-1]);
	} main {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		}
		System.out.println(dp[N-1]);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int K=sc.nextInt(); K sc.nextInt() sc.nextInt sc int h[]=new int[N]; h new int[N] N for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			h[i]=sc.nextInt();
		} {
			h[i]=sc.nextInt();
		} h[i]=sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int dp[]=new int[N]; dp new int[N] N dp[0]=0 dp[0] dp 0 0 for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		} int j=1; int j=1; j 1 j<N j N j++ j++ j {
			dp[j]=Integer.MAX_VALUE;
		} {
			dp[j]=Integer.MAX_VALUE;
		} dp[j]=Integer.MAX_VALUE dp[j] dp j Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int k=0;k<N;k++) {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		} int k=0; int k=0; k 0 k<N k N k++ k++ k {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		} {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		} for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			} int l=k+1; int l=k+1; l k+1 k 1 l<k+K+1 l k+K+1 k+K+1 k K 1 l++ l++ l {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			} {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			} if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				} l<N l N {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				} dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k])) dp[l] dp l Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k])) Math.min Math dp[l] dp l dp[k]+Math.abs(h[l]-h[k]) dp[k] dp k Math.abs(h[l]-h[k]) Math.abs Math h[l]-h[k] h[l] h l h[k] h k 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
import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		}
		System.out.println(dp[N-1]);
	}
}