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

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String[] temp = in.nextLine().trim().split("\\s");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        // System.out.println(Arrays.toString(h));
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    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.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String[] temp = in.nextLine().trim().split("\\s");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        // System.out.println(Arrays.toString(h));
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        }
        System.out.println(dp[n-1]);
    }
} Main public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String[] temp = in.nextLine().trim().split("\\s");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        // System.out.println(Arrays.toString(h));
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        }
        System.out.println(dp[n-1]);
    } main {
        Scanner in = new Scanner(System.in);
        String[] temp = in.nextLine().trim().split("\\s");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        // System.out.println(Arrays.toString(h));
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        }
        System.out.println(dp[n-1]);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) String[] temp = in.nextLine().trim().split("\\s"); temp in.nextLine().trim().split("\\s") in.nextLine().trim().split in.nextLine().trim() in.nextLine().trim in.nextLine() in.nextLine in "\\s" int n = Integer.parseInt(temp[0]); n Integer.parseInt(temp[0]) Integer.parseInt Integer temp[0] temp 0 int k = Integer.parseInt(temp[1]); k Integer.parseInt(temp[1]) Integer.parseInt Integer temp[1] temp 1 int[] h = new int[n]; h new int[n] n int count = 0; count 0 for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        } String a in.nextLine().trim().split("\\s") in.nextLine().trim().split in.nextLine().trim() in.nextLine().trim in.nextLine() in.nextLine in "\\s" {
            h[count++] = Integer.parseInt(a);
        } {
            h[count++] = Integer.parseInt(a);
        } h[count++] = Integer.parseInt(a) h[count++] h count++ count Integer.parseInt(a) Integer.parseInt Integer a int[] dp = new int[n]; dp new int[n] n for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    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 {
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        } {
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        } dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    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 j k j++ j++ j {
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            } {
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            } if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                } i-j >= 0 i-j i j 0 {
                    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 String[] args args public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String[] temp = in.nextLine().trim().split("\\s");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        // System.out.println(Arrays.toString(h));
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        }
        System.out.println(dp[n-1]);
    }
} public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String[] temp = in.nextLine().trim().split("\\s");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        // System.out.println(Arrays.toString(h));
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[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 in = new Scanner(System.in);
        String[] temp = in.nextLine().trim().split("\\s");
        int n = Integer.parseInt(temp[0]);
        int k = Integer.parseInt(temp[1]);
        
        int[] h = new int[n];
        int count = 0;
        for(String a : in.nextLine().trim().split("\\s")){
            h[count++] = Integer.parseInt(a);
        }
        // System.out.println(Arrays.toString(h));
        int[] dp = new int[n];
        for(int i = 1; i < n; i++){
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i-j >= 0){
                    dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
                }
            }
        }
        System.out.println(dp[n-1]);
    }
}