import java.util.Scanner;

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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[N-1]);
    }
} import java.util.Scanner; Scanner 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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[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 int[] dp = new int[N]; dp new int[N] N for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            dp[i] = (int) Math.pow(10, 9);
        } {
            dp[i] = (int) Math.pow(10, 9);
        } dp[i] = (int) Math.pow(10, 9) dp[i] dp i (int) Math.pow(10, 9) Math.pow Math 10 9 dp[0] = 0 dp[0] dp 0 0 for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        } int x=0; int x=0; x 0 x<N-1 x N-1 N 1 x++ x++ x {
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        } {
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        } for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            } int b=1; int b=1; b 1 b<=K b K b++ b++ b {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            } {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            } if(x+b >= dp.length) {
                    continue;
                } x+b >= dp.length x+b x b dp.length dp dp.length {
                    continue;
                } continue; dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x])) dp[x+b] dp x+b x b Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x])) Math.min Math dp[x+b] dp x+b x b dp[x] + Math.abs(h[x+b] - h[x]) dp[x] dp x Math.abs(h[x+b] - h[x]) Math.abs Math h[x+b] - h[x] h[x+b] h x+b x b h[x] h x 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 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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[N-1]);
    }
} Main
import java.util.Scanner;

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();
        }

        int[] dp = new int[N];
        for(int i=0; i<N; i++) {
            dp[i] = (int) Math.pow(10, 9);
        }

        dp[0] = 0;

        for(int x=0; x<N-1; x++){
            for(int b=1; b<=K; b++) {
                if(x+b >= dp.length) {
                    continue;
                }
                dp[x+b] = Math.min(dp[x+b], dp[x] + Math.abs(h[x+b] - h[x]));
            }
        }

        System.out.println(dp[N-1]);
    }
}