import java.util.Scanner;

public class Main {
    static public void main(String args[]){
        final int INF = (int)1e10;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long[] h = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        }
        dp[0] = 0;

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

        System.out.println(dp[n-1]);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    static public void main(String args[]){
        final int INF = (int)1e10;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long[] h = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        }
        dp[0] = 0;

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

        System.out.println(dp[n-1]);
    }
} Main static public void main(String args[]){
        final int INF = (int)1e10;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long[] h = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        }
        dp[0] = 0;

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

        System.out.println(dp[n-1]);
    } main {
        final int INF = (int)1e10;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long[] h = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        }
        dp[0] = 0;

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

        System.out.println(dp[n-1]);
    } final int INF = (int)1e10; INF (int)1e10 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 long[] h = new long[n]; h new long[n] n long[] dp = new long[n]; dp new long[n] n for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] = sc.nextLong();
            dp[i] = INF;
        } {
            h[i] = sc.nextLong();
            dp[i] = INF;
        } h[i] = sc.nextLong() h[i] h i sc.nextLong() sc.nextLong sc dp[i] = INF dp[i] dp i INF dp[0] = 0 dp[0] dp 0 0 for(int i = 0 ; i < n-1 ; i++){
            for(int j = 1 ; j <= k ; j++) {
                if (i + j < n) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                }
            }
        } int i = 0 ; int i = 0 ; i 0 i < n-1 i n-1 n 1 i++ i++ i {
            for(int j = 1 ; j <= k ; j++) {
                if (i + j < n) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                }
            }
        } {
            for(int j = 1 ; j <= k ; j++) {
                if (i + j < n) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                }
            }
        } for(int j = 1 ; j <= k ; j++) {
                if (i + j < n) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                }
            } int j = 1 ; int j = 1 ; j 1 j <= k j k j++ j++ j {
                if (i + j < n) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                }
            } {
                if (i + j < n) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                }
            } if (i + j < n) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                } i + j < n i + j i j n {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
                } dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i])) dp[i + j] dp i + j i j Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i])) Math.min Math dp[i + j] dp i + j i j 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 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 {
    static public void main(String args[]){
        final int INF = (int)1e10;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long[] h = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        }
        dp[0] = 0;

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

        System.out.println(dp[n-1]);
    }
} public class Main {
    static public void main(String args[]){
        final int INF = (int)1e10;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long[] h = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        }
        dp[0] = 0;

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

        System.out.println(dp[n-1]);
    }
} Main
import java.util.Scanner;

public class Main {
    static public void main(String args[]){
        final int INF = (int)1e10;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long[] h = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i < n ; i++){
            h[i] = sc.nextLong();
            dp[i] = INF;
        }
        dp[0] = 0;

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

        System.out.println(dp[n-1]);
    }
}
