
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static long n = sc.nextLong();
    static long k = sc.nextLong();
    static long h[] = new long[(int)n];
    static long dp[] = new long[(int)n];
    public static void main(String[] args) {
        //初期化
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        }
        System.out.println(dp[(int)n - 1]);
    }
    public static long chmin(long a, long b){
        if (a > b){
            return b;
        } else {
            return a;
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    static Scanner sc = new Scanner(System.in);
    static long n = sc.nextLong();
    static long k = sc.nextLong();
    static long h[] = new long[(int)n];
    static long dp[] = new long[(int)n];
    public static void main(String[] args) {
        //初期化
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        }
        System.out.println(dp[(int)n - 1]);
    }
    public static long chmin(long a, long b){
        if (a > b){
            return b;
        } else {
            return a;
        }
    }
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc static long k = sc.nextLong(); k sc.nextLong() sc.nextLong sc static long h[] = new long[(int)n]; h new long[(int)n] (int)n static long dp[] = new long[(int)n]; dp new long[(int)n] (int)n public static void main(String[] args) {
        //初期化
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        }
        System.out.println(dp[(int)n - 1]);
    } main {
        //初期化
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        }
        System.out.println(dp[(int)n - 1]);
    } for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        } {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc dp[i] = 2147483647 dp[i] dp i 2147483647 dp[0] = 0 dp[0] dp 0 0 for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(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] = chmin(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] = chmin(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] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            } {
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            } if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i])); i + j < n i + j i j n dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i])) dp[i + j] dp i + j i j chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i])) chmin 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[(int)n - 1]) System.out.println System.out System System.out dp[(int)n - 1] dp (int)n - 1 (int)n 1 String[] args args public static long chmin(long a, long b){
        if (a > b){
            return b;
        } else {
            return a;
        }
    } chmin {
        if (a > b){
            return b;
        } else {
            return a;
        }
    } if (a > b){
            return b;
        } else {
            return a;
        } a > b a b {
            return b;
        } return b; b {
            return a;
        } return a; a long a a long b b public class Main {
    static Scanner sc = new Scanner(System.in);
    static long n = sc.nextLong();
    static long k = sc.nextLong();
    static long h[] = new long[(int)n];
    static long dp[] = new long[(int)n];
    public static void main(String[] args) {
        //初期化
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        }
        System.out.println(dp[(int)n - 1]);
    }
    public static long chmin(long a, long b){
        if (a > b){
            return b;
        } else {
            return a;
        }
    }
} public class Main {
    static Scanner sc = new Scanner(System.in);
    static long n = sc.nextLong();
    static long k = sc.nextLong();
    static long h[] = new long[(int)n];
    static long dp[] = new long[(int)n];
    public static void main(String[] args) {
        //初期化
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        }
        System.out.println(dp[(int)n - 1]);
    }
    public static long chmin(long a, long b){
        if (a > b){
            return b;
        } else {
            return a;
        }
    }
} Main

import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static long n = sc.nextLong();
    static long k = sc.nextLong();
    static long h[] = new long[(int)n];
    static long dp[] = new long[(int)n];
    public static void main(String[] args) {
        //初期化
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < n)
                    dp[i + j] = chmin(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]));
            }
        }
        System.out.println(dp[(int)n - 1]);
    }
    public static long chmin(long a, long b){
        if (a > b){
            return b;
        } else {
            return a;
        }
    }
}
