import java.util.Scanner;
 
class Main {
	int n;
	int k;
	int[] h;
	long[] dp;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		k = sc.nextInt();
		h = new int[n];
		dp = new long[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		}
		dp[0] = 0;
	}
	void solve(){
		for(int i=1;i<n;i++){
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		}
		System.out.println(dp[n-1]);
	}
} import java.util.Scanner; Scanner java.util class Main {
	int n;
	int k;
	int[] h;
	long[] dp;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		k = sc.nextInt();
		h = new int[n];
		dp = new long[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		}
		dp[0] = 0;
	}
	void solve(){
		for(int i=1;i<n;i++){
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		}
		System.out.println(dp[n-1]);
	}
} Main int n; n int k; k int[] h; h long[] dp; dp public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	} main {
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Main m = new Main(sc); m new Main(sc) m.solve() m.solve m String[] args args Main(Scanner sc){
		n = sc.nextInt();
		k = sc.nextInt();
		h = new int[n];
		dp = new long[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		}
		dp[0] = 0;
	} Main {
		n = sc.nextInt();
		k = sc.nextInt();
		h = new int[n];
		dp = new long[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		}
		dp[0] = 0;
	} n = sc.nextInt() n sc.nextInt() sc.nextInt sc k = sc.nextInt() k sc.nextInt() sc.nextInt sc h = new int[n] h new int[n] n dp = new long[n] dp new long[n] n for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		} {
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc dp[i] = Long.MAX_VALUE dp[i] dp i Long.MAX_VALUE Long Long.MAX_VALUE dp[0] = 0 dp[0] dp 0 0 Scanner sc sc void solve(){
		for(int i=1;i<n;i++){
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		}
		System.out.println(dp[n-1]);
	} solve {
		for(int i=1;i<n;i++){
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		}
		System.out.println(dp[n-1]);
	} for(int i=1;i<n;i++){
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		} {
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		} for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			} int j=1; int j=1; j 1 j<=k&&(i-j)>=0 j<=k j k (i-j)>=0 (i-j) i j 0 j++ j++ j {
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			} {
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			} dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j])) dp[i] dp i Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j])) Math.min Math dp[i] dp i dp[i-j]+Math.abs(h[i]-h[i-j]) dp[i-j] dp i-j i j Math.abs(h[i]-h[i-j]) Math.abs Math h[i]-h[i-j] h[i] h i h[i-j] h i-j i j System.out.println(dp[n-1]) System.out.println System.out System System.out dp[n-1] dp n-1 n 1
import java.util.Scanner;
 
class Main {
	int n;
	int k;
	int[] h;
	long[] dp;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		k = sc.nextInt();
		h = new int[n];
		dp = new long[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
			dp[i] = Long.MAX_VALUE;
		}
		dp[0] = 0;
	}
	void solve(){
		for(int i=1;i<n;i++){
			for(int j=1;j<=k&&(i-j)>=0;j++){
				dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
			}
		}
		System.out.println(dp[n-1]);
	}
}