import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a,k);
		
		System.out.println(ans);
	}

	private 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 = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		}
		
		return dp[a.length-1];
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a,k);
		
		System.out.println(ans);
	}

	private 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 = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		}
		
		return dp[a.length-1];
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a,k);
		
		System.out.println(ans);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a,k);
		
		System.out.println(ans);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] nk = br.readLine().split(" "); nk br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(nk[0]); n Integer.parseInt(nk[0]) Integer.parseInt Integer nk[0] nk 0 int k = Integer.parseInt(nk[1]); k Integer.parseInt(nk[1]) Integer.parseInt Integer nk[1] nk 1 int[] a = new int[n]; a new int[n] n String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		} int i = 0; int i = 0; i 0 i < input.length i input.length input input.length i++ i++ i {
			a[i] = Integer.parseInt(input[i]);
		} {
			a[i] = Integer.parseInt(input[i]);
		} a[i] = Integer.parseInt(input[i]) a[i] a i Integer.parseInt(input[i]) Integer.parseInt Integer input[i] input i int ans = solve(a,k); ans solve(a,k) solve a k System.out.println(ans) System.out.println System.out System System.out ans String[] args args private 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 = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		}
		
		return dp[a.length-1];
	} solve {
		
		int[] dp = new int[a.length];
		
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		
		for (int i = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		}
		
		return dp[a.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 = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		} int i = 0; int i = 0; i 0 i < dp.length i dp.length dp dp.length i++ i++ i {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		} {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		} for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			} int j = i+1; int j = i+1; j i+1 i 1 j < Math.min(dp.length, i+k+1) j Math.min(dp.length, i+k+1) Math.min Math dp.length dp dp.length i+k+1 i+k+1 i k 1 j++ j++ j {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			} {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			} dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j])) dp[j] dp j Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j])) Math.min Math dp[j] dp j dp[i]+Math.abs(a[i]-a[j]) dp[i] dp i Math.abs(a[i]-a[j]) Math.abs Math a[i]-a[j] a[i] a i a[j] a j return dp[a.length-1]; dp[a.length-1] dp a.length-1 a.length a a.length 1 int[] a a int k k public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a,k);
		
		System.out.println(ans);
	}

	private 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 = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		}
		
		return dp[a.length-1];
	}
} public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a,k);
		
		System.out.println(ans);
	}

	private 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 = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		}
		
		return dp[a.length-1];
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a,k);
		
		System.out.println(ans);
	}

	private 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 = 0; i < dp.length; i++) {
			
			for (int j = i+1; j < Math.min(dp.length, i+k+1); j++) {
				dp[j] = Math.min(dp[j], dp[i]+Math.abs(a[i]-a[j]));
			}
			
		}
		
		return dp[a.length-1];
	}
}