import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; 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.*; util.* java public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; 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 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args void run() {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; 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]);

    } run {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; 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]);

    } 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] h i sc.nextInt() sc.nextInt sc int[] dp = new int[n+1]; dp new int[n+1] n+1 n 1 for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE; int i=1; int i=1; i 1 i<n+1 i n+1 n 1 i++ i++ i dp[i] = Integer.MAX_VALUE; dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i=0; i<n; 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 i n 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] 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 public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; 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 {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; 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.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; 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]);

    }
}


