import java.util.*;

public class Main {
    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    }
    public static int solve(int[] stones , int[] dp , int n , int k ){
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    }

}
 import java.util.*; util.* java public class Main {
    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    }
    public static int solve(int[] stones , int[] dp , int n , int k ){
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    }

} Main public static Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    } main {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    } int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int k = scanner.nextInt(); k scanner.nextInt() scanner.nextInt scanner int stones[] = new int[n+1]; stones new int[n+1] n+1 n 1 int dp[] = new int[n+1]; dp new int[n+1] n+1 n 1 for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        } int i = 1 ; int i = 1 ; i 1 i <= n i n i++ i++ i {
            stones[i] = scanner.nextInt();
        } {
            stones[i] = scanner.nextInt();
        } stones[i] = scanner.nextInt() stones[i] stones i scanner.nextInt() scanner.nextInt scanner System.out.println(solve(stones,dp,n,k)) System.out.println System.out System System.out solve(stones,dp,n,k) solve stones dp n k String[] args args public static int solve(int[] stones , int[] dp , int n , int k ){
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    } solve {
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    } if(n <=1){
            return 0;
        } n <=1 n 1 {
            return 0;
        } return 0; 0 for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        } int i = 2 ; int i = 2 ; i 2 i<= n i n i++ i++ i {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        } {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        } dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            } int j = i-1 ; int j = i-1 ; j i-1 i 1 j >= 1 && (i-j) <= k j >= 1 j 1 (i-j) <= k (i-j) i j k j-- j-- j {
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            } {
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            } dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]) dp[i] dp i Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]) Math.min Math dp[i] dp i Math.abs(stones[i] - stones[j]) + dp[j] Math.abs(stones[i] - stones[j]) Math.abs Math stones[i] - stones[j] stones[i] stones i stones[j] stones j dp[j] dp j return dp[n]; dp[n] dp n int[] stones stones int[] dp dp int n n int k k public class Main {
    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    }
    public static int solve(int[] stones , int[] dp , int n , int k ){
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    }

} public class Main {
    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    }
    public static int solve(int[] stones , int[] dp , int n , int k ){
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    }

} Main
import java.util.*;

public class Main {
    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    }
    public static int solve(int[] stones , int[] dp , int n , int k ){
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    }

}

