import java.util.Arrays;
import java.util.Scanner;

public 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();
		}
		long dp[] = new long[n];
		Arrays.fill(dp, Integer.MAX_VALUE);

		for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		}
		System.out.println(dp[n - 1]);

	}


}
 import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public 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();
		}
		long dp[] = new long[n];
		Arrays.fill(dp, Integer.MAX_VALUE);

		for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		}
		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();
		}
		long dp[] = new long[n];
		Arrays.fill(dp, Integer.MAX_VALUE);

		for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		}
		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();
		}
		long dp[] = new long[n];
		Arrays.fill(dp, Integer.MAX_VALUE);

		for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		}
		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 long dp[] = new long[n]; dp new long[n] n Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		} int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		} {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		} if(i == 0)
				dp[i] = 0; i == 0 i 0 dp[i] = 0 dp[i] dp i 0 for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			} int j = k ; int j = k ; j k j > 0 j 0 j-- j-- j {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			} {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			} if(i + j >= n)
                continue; i + j >= n i + j i j n continue; dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]) dp[i + j] dp i + j i j Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]) Math.min Math dp[i] + Math.abs(h[i + j] - h[i]) dp[i] dp i Math.abs(h[i + j] - h[i]) Math.abs Math h[i + j] - h[i] h[i + j] h i + j i j h[i] h i dp[i + j] dp 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 String[] args args public 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();
		}
		long dp[] = new long[n];
		Arrays.fill(dp, Integer.MAX_VALUE);

		for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		}
		System.out.println(dp[n - 1]);

	}


} public 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();
		}
		long dp[] = new long[n];
		Arrays.fill(dp, Integer.MAX_VALUE);

		for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		}
		System.out.println(dp[n - 1]);

	}


} Main
import java.util.Arrays;
import java.util.Scanner;

public 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();
		}
		long dp[] = new long[n];
		Arrays.fill(dp, Integer.MAX_VALUE);

		for(int i = 0 ; i < n ; i++) {
			if(i == 0)
				dp[i] = 0;
			for(int j = k ; j > 0 ; j--) {
              if(i + j >= n)
                continue;
				dp[i + j] = Math.min(dp[i] + Math.abs(h[i + j] - h[i]), dp[i + j]);
			}
		}
		System.out.println(dp[n - 1]);

	}


}

