import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int k = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , (int)Math.pow(10 , 9));
                q[0] = 0;
                for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                }
                System.out.println(q[n - 1]);
        }
} import java.util.*; util.* java public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int k = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , (int)Math.pow(10 , 9));
                q[0] = 0;
                for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                }
                System.out.println(q[n - 1]);
        }
} Main public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int k = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , (int)Math.pow(10 , 9));
                q[0] = 0;
                for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                }
                System.out.println(q[n - 1]);
        } main {
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int k = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , (int)Math.pow(10 , 9));
                q[0] = 0;
                for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                }
                System.out.println(q[n - 1]);
        } 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 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] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int[] q = new int[n]; q new int[n] n Arrays.fill(q , (int)Math.pow(10 , 9)) Arrays.fill Arrays q (int)Math.pow(10 , 9) Math.pow Math 10 9 q[0] = 0 q[0] q 0 0 for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                } {
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                } for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        } int j = 1 ; int j = 1 ; j 1 j <= Math.min(k , i) j Math.min(k , i) Math.min Math k i j++ j++ j {
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        } {
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        } q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j])) q[i] q i Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j])) Math.min Math q[i] q i q[i - j] + Math.abs(h[i] - h[i - j]) q[i - j] q i - j i j Math.abs(h[i] - h[i - j]) Math.abs Math h[i] - h[i - j] h[i] h i h[i - j] h i - j i j System.out.println(q[n - 1]) System.out.println System.out System System.out q[n - 1] q n - 1 n 1 String[] args args public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int k = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , (int)Math.pow(10 , 9));
                q[0] = 0;
                for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                }
                System.out.println(q[n - 1]);
        }
} public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int k = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , (int)Math.pow(10 , 9));
                q[0] = 0;
                for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                }
                System.out.println(q[n - 1]);
        }
} Main
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int k = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , (int)Math.pow(10 , 9));
                q[0] = 0;
                for(int i = 1; i < n ; i++){
                        for(int j = 1 ; j <= Math.min(k , i) ; j++){
                                q[i] = Math.min(q[i] , q[i - j] + Math.abs(h[i] - h[i - j]));
                        }
                }
                System.out.println(q[n - 1]);
        }
}