import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.jar.JarOutputStream;

public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int k= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);

    }

}






class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

}
 import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.lang.reflect.Array; Array java.lang.reflect import java.util.*; util.* java import java.util.jar.JarOutputStream; JarOutputStream java.util.jar public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int k= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);

    }

} Main public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    } lower_bound {
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    } int low = 0; low 0 int high = arr.length - 1; high arr.length - 1 arr.length arr arr.length 1 while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        } low < high low high {
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        } int mid = (low + high) / 2; mid (low + high) / 2 (low + high) low high 2 if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            } arr[mid] < target arr[mid] arr mid target {
                low = mid + 1;
            } low = mid + 1 low mid + 1 mid 1 {
                high = mid;
            } high = mid high mid return low; low long[] arr arr long target target public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int k= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);

    } main {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int k= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);

    } Reader.init(System.in) Reader.init Reader System.in System System.in int n= Reader.nextInt(); n Reader.nextInt() Reader.nextInt Reader int k= Reader.nextInt(); k Reader.nextInt() Reader.nextInt Reader int[] cost=Reader.nextIntArray(n); cost Reader.nextIntArray(n) Reader.nextIntArray Reader n int[] dp=new int[n]; dp new int[n] n dp[0]=0 dp[0] dp 0 0 if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        } dp.length>1 dp.length dp dp.length 1 {
            dp[1]=Math.abs(cost[1]-cost[0]);
        } dp[1]=Math.abs(cost[1]-cost[0]) dp[1] dp 1 Math.abs(cost[1]-cost[0]) Math.abs Math cost[1]-cost[0] cost[1] cost 1 cost[0] cost 0 for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        } int i=2; int i=2; i 2 i<dp.length i dp.length dp dp.length i++ i++ i {
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        } {
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        } int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            } {
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            } if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                } i-j>=0 i-j i j 0 {
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                } min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j])) min Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j])) Math.min Math min dp[i-j]+Math.abs(cost[i]-cost[i-j]) dp[i-j] dp i-j i j Math.abs(cost[i]-cost[i-j]) Math.abs Math cost[i]-cost[i-j] cost[i] cost i cost[i-j] cost i-j i j dp[i]=min dp[i] dp i min 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 class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

} Reader static BufferedReader reader; reader static StringTokenizer tokenizer; tokenizer /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    } init {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    } reader = new BufferedReader(
                new InputStreamReader(input) ) reader new BufferedReader(
                new InputStreamReader(input) ) tokenizer = new StringTokenizer("") tokenizer new StringTokenizer("") InputStream input input /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    } nextLine {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    } while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        } ! tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        } tokenizer = new StringTokenizer(
                    reader.readLine() ) tokenizer new StringTokenizer(
                    reader.readLine() ) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    } nextInt {
        return Integer.parseInt( nextLine() );
    } return Integer.parseInt( nextLine() ); Integer.parseInt( nextLine() ) Integer.parseInt Integer nextLine() nextLine static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    } nextLong {
        return Long.parseLong(nextLine());
    } return Long.parseLong(nextLine()); Long.parseLong(nextLine()) Long.parseLong Long nextLine() nextLine static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    } nextDouble {
        return Double.parseDouble( nextLine() );
    } return Double.parseDouble( nextLine() ); Double.parseDouble( nextLine() ) Double.parseDouble Double nextLine() nextLine static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    } nextFloat {
        return Float.parseFloat( nextLine() );
    } return Float.parseFloat( nextLine() ); Float.parseFloat( nextLine() ) Float.parseFloat Float nextLine() nextLine static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    } nextIntArray {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    } int[] arr = new int[length]; arr new int[length] length for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        } int i=0; int i=0; i 0 i<length i length i++ i++ i {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        } {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        } arr[i] = Integer.parseInt( nextLine() ) arr[i] arr i Integer.parseInt( nextLine() ) Integer.parseInt Integer nextLine() nextLine return arr; arr int length length static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    } nextLongArray {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    } long[] arr = new long[length]; arr new long[length] length for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        } int i=0; int i=0; i 0 i<length i length i++ i++ i {
            arr[i] = Long.parseLong( nextLine() );
        } {
            arr[i] = Long.parseLong( nextLine() );
        } arr[i] = Long.parseLong( nextLine() ) arr[i] arr i Long.parseLong( nextLine() ) Long.parseLong Long nextLine() nextLine return arr; arr int length length public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int k= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);

    }

} public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int k= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);

    }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.jar.JarOutputStream;

public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int k= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            int min = Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min = Math.min(min,dp[i-j]+Math.abs(cost[i]-cost[i-j]));
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);

    }

}






class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

}

