import java.util.*;
import java.util.Arrays;

public class Main {
    public static long a = (long)Math.pow(2, 60);
    public static long[] lst;
    public static long[] height;
    public static int K;
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        //System.out.println(a);
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        K = sc.nextInt();
        
        lst = new long[N];
        
        Arrays.fill(lst, a);
        
        lst[0] = 0;
        
        //System.out.println(lst[0]);
        
        height = new long[N];
        
        for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        }
        
        //System.out.println(height[1]);
        
        //System.out.println(tilAns(N));
        System.out.println(tilAns(N-1));
    }
    static long tilAns(int n){
        if (lst[n] != a) {
            return lst[n];
        }
        
        if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        }
        long mini = a;
        for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        }
        lst[n] = mini;
        return lst[n];
    }
} import java.util.*; util.* java import java.util.Arrays; Arrays java.util public class Main {
    public static long a = (long)Math.pow(2, 60);
    public static long[] lst;
    public static long[] height;
    public static int K;
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        //System.out.println(a);
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        K = sc.nextInt();
        
        lst = new long[N];
        
        Arrays.fill(lst, a);
        
        lst[0] = 0;
        
        //System.out.println(lst[0]);
        
        height = new long[N];
        
        for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        }
        
        //System.out.println(height[1]);
        
        //System.out.println(tilAns(N));
        System.out.println(tilAns(N-1));
    }
    static long tilAns(int n){
        if (lst[n] != a) {
            return lst[n];
        }
        
        if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        }
        long mini = a;
        for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        }
        lst[n] = mini;
        return lst[n];
    }
} Main public static long a = (long)Math.pow(2, 60); a (long)Math.pow(2, 60) Math.pow Math 2 60 public static long[] lst; lst public static long[] height; height public static int K; K public static void main(String[] args) throws Exception {
        // Your code here!
        
        //System.out.println(a);
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        K = sc.nextInt();
        
        lst = new long[N];
        
        Arrays.fill(lst, a);
        
        lst[0] = 0;
        
        //System.out.println(lst[0]);
        
        height = new long[N];
        
        for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        }
        
        //System.out.println(height[1]);
        
        //System.out.println(tilAns(N));
        System.out.println(tilAns(N-1));
    } main {
        // Your code here!
        
        //System.out.println(a);
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        K = sc.nextInt();
        
        lst = new long[N];
        
        Arrays.fill(lst, a);
        
        lst[0] = 0;
        
        //System.out.println(lst[0]);
        
        height = new long[N];
        
        for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        }
        
        //System.out.println(height[1]);
        
        //System.out.println(tilAns(N));
        System.out.println(tilAns(N-1));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc K = sc.nextInt() K sc.nextInt() sc.nextInt sc lst = new long[N] lst new long[N] N Arrays.fill(lst, a) Arrays.fill Arrays lst a lst[0] = 0 lst[0] lst 0 0 height = new long[N] height new long[N] N for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            height[i] = sc.nextInt();
        } {
            height[i] = sc.nextInt();
        } height[i] = sc.nextInt() height[i] height i sc.nextInt() sc.nextInt sc System.out.println(tilAns(N-1)) System.out.println System.out System System.out tilAns(N-1) tilAns N-1 N 1 String[] args args static long tilAns(int n){
        if (lst[n] != a) {
            return lst[n];
        }
        
        if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        }
        long mini = a;
        for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        }
        lst[n] = mini;
        return lst[n];
    } tilAns {
        if (lst[n] != a) {
            return lst[n];
        }
        
        if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        }
        long mini = a;
        for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        }
        lst[n] = mini;
        return lst[n];
    } if (lst[n] != a) {
            return lst[n];
        } lst[n] != a lst[n] lst n a {
            return lst[n];
        } return lst[n]; lst[n] lst n if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        } n < K n K {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        } long mini = a; mini a for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            } {
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            } if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                } mini > tilAns(i) + Math.abs(height[n] - height[i]) mini tilAns(i) + Math.abs(height[n] - height[i]) tilAns(i) tilAns i Math.abs(height[n] - height[i]) Math.abs Math height[n] - height[i] height[n] height n height[i] height i {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                } mini = tilAns(i) + Math.abs(height[n] - height[i]) mini tilAns(i) + Math.abs(height[n] - height[i]) tilAns(i) tilAns i Math.abs(height[n] - height[i]) Math.abs Math height[n] - height[i] height[n] height n height[i] height i lst[n] = mini lst[n] lst n mini return lst[n]; lst[n] lst n long mini = a; mini a for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        } int i = 1; int i = 1; i 1 i<=K i K i++ i++ i {
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        } {
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        } if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            } mini > tilAns(n-i) + Math.abs(height[n] - height[n-i]) mini tilAns(n-i) + Math.abs(height[n] - height[n-i]) tilAns(n-i) tilAns n-i n i Math.abs(height[n] - height[n-i]) Math.abs Math height[n] - height[n-i] height[n] height n height[n-i] height n-i n i {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            } mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]) mini tilAns(n-i) + Math.abs(height[n] - height[n-i]) tilAns(n-i) tilAns n-i n i Math.abs(height[n] - height[n-i]) Math.abs Math height[n] - height[n-i] height[n] height n height[n-i] height n-i n i lst[n] = mini lst[n] lst n mini return lst[n]; lst[n] lst n int n n public class Main {
    public static long a = (long)Math.pow(2, 60);
    public static long[] lst;
    public static long[] height;
    public static int K;
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        //System.out.println(a);
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        K = sc.nextInt();
        
        lst = new long[N];
        
        Arrays.fill(lst, a);
        
        lst[0] = 0;
        
        //System.out.println(lst[0]);
        
        height = new long[N];
        
        for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        }
        
        //System.out.println(height[1]);
        
        //System.out.println(tilAns(N));
        System.out.println(tilAns(N-1));
    }
    static long tilAns(int n){
        if (lst[n] != a) {
            return lst[n];
        }
        
        if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        }
        long mini = a;
        for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        }
        lst[n] = mini;
        return lst[n];
    }
} public class Main {
    public static long a = (long)Math.pow(2, 60);
    public static long[] lst;
    public static long[] height;
    public static int K;
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        //System.out.println(a);
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        K = sc.nextInt();
        
        lst = new long[N];
        
        Arrays.fill(lst, a);
        
        lst[0] = 0;
        
        //System.out.println(lst[0]);
        
        height = new long[N];
        
        for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        }
        
        //System.out.println(height[1]);
        
        //System.out.println(tilAns(N));
        System.out.println(tilAns(N-1));
    }
    static long tilAns(int n){
        if (lst[n] != a) {
            return lst[n];
        }
        
        if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        }
        long mini = a;
        for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        }
        lst[n] = mini;
        return lst[n];
    }
} Main
import java.util.*;
import java.util.Arrays;

public class Main {
    public static long a = (long)Math.pow(2, 60);
    public static long[] lst;
    public static long[] height;
    public static int K;
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        //System.out.println(a);
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        K = sc.nextInt();
        
        lst = new long[N];
        
        Arrays.fill(lst, a);
        
        lst[0] = 0;
        
        //System.out.println(lst[0]);
        
        height = new long[N];
        
        for (int i=0; i<N; i++) {
            height[i] = sc.nextInt();
        }
        
        //System.out.println(height[1]);
        
        //System.out.println(tilAns(N));
        System.out.println(tilAns(N-1));
    }
    static long tilAns(int n){
        if (lst[n] != a) {
            return lst[n];
        }
        
        if (n < K) {
            long mini = a;
            for (int i = 0; i<n; i++){
                if (mini > tilAns(i) + Math.abs(height[n] - height[i])) {
                    mini = tilAns(i) + Math.abs(height[n] - height[i]);
                }
            }
            lst[n] = mini;
            return lst[n];
        }
        long mini = a;
        for (int i = 1; i<=K; i++){
            if (mini > tilAns(n-i) + Math.abs(height[n] - height[n-i])) {
                mini = tilAns(n-i) + Math.abs(height[n] - height[n-i]);
            }
            
        }
        lst[n] = mini;
        return lst[n];
    }
}
