import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		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[] cost = new int[N];
		cost[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		}
		pw.println(cost[0]);
		// end

		sc.close();
		pw.close();
	}
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		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[] cost = new int[N];
		cost[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		}
		pw.println(cost[0]);
		// end

		sc.close();
		pw.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		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[] cost = new int[N];
		cost[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		}
		pw.println(cost[0]);
		// end

		sc.close();
		pw.close();
	} main {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		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[] cost = new int[N];
		cost[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		}
		pw.println(cost[0]);
		// end

		sc.close();
		pw.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter pw = new PrintWriter(System.out); pw new PrintWriter(System.out) 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[] cost = new int[N]; cost new int[N] N cost[N - 1] = 0 cost[N - 1] cost N - 1 N 1 0 for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		} int i = N - 2; int i = N - 2; i N - 2 N 2 i >= 0 i 0 i-- i-- i {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		} {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		} int temp = K + 1; temp K + 1 K 1 cost[i] = Integer.MAX_VALUE cost[i] cost i Integer.MAX_VALUE Integer Integer.MAX_VALUE while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			} temp-- > 1 temp-- temp 1 {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			} if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				} i + temp <= N - 1 i + temp i temp N - 1 N 1 {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				} cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i])) cost[i] cost i Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i])) Math.min Math cost[i] cost i cost[i + temp] + Math.abs(h[i + temp] - h[i]) cost[i + temp] cost i + temp i temp Math.abs(h[i + temp] - h[i]) Math.abs Math h[i + temp] - h[i] h[i + temp] h i + temp i temp h[i] h i pw.println(cost[0]) pw.println pw cost[0] cost 0 sc.close() sc.close sc pw.close() pw.close pw String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		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[] cost = new int[N];
		cost[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		}
		pw.println(cost[0]);
		// end

		sc.close();
		pw.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		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[] cost = new int[N];
		cost[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		}
		pw.println(cost[0]);
		// end

		sc.close();
		pw.close();
	}
} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		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[] cost = new int[N];
		cost[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
//			if(i == N-2)cost[i]=Math.abs(h[i+1]-h[i]);
			int temp = K + 1;
			cost[i] = Integer.MAX_VALUE;
			while (temp-- > 1) {
				if (i + temp <= N - 1) {
//					System.out.println(":::"+i+":"+temp);
					cost[i] = Math.min(cost[i], cost[i + temp] + Math.abs(h[i + temp] - h[i]));
				}
			}
		}
		pw.println(cost[0]);
		// end

		sc.close();
		pw.close();
	}
}
