import java.util.Arrays;
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];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        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] - h[i+j]));
                }
            }
        }

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

} import java.util.Arrays; Arrays java.util 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];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        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] - h[i+j]));
                }
            }
        }

        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];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        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] - h[i+j]));
                }
            }
        }

        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];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        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] - h[i+j]));
                }
            }
        }

        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 int[] dp = new int[N]; dp 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 Arrays.fill(dp, (int)2e9) Arrays.fill Arrays dp (int)2e9 dp[0] = 0 dp[0] dp 0 0 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] - h[i+j]));
                }
            }
        } 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] - h[i+j]));
                }
            }
        } {
            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] - h[i+j]));
                }
            }
        } 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] - h[i+j]));
                }
            } 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] - h[i+j]));
                }
            } {
                if (i + j < N) {
                    dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(h[i] - h[i+j]));
                }
            } if (i + j < N) {
                    dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(h[i] - h[i+j]));
                } i + j < N i + j i j N {
                    dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(h[i] - h[i+j]));
                } dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(h[i] - h[i+j])) dp[i+j] dp i+j i j Math.min(dp[i+j], dp[i] + Math.abs(h[i] - h[i+j])) Math.min Math dp[i+j] dp i+j i j dp[i] + Math.abs(h[i] - h[i+j]) dp[i] dp i 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(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];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        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] - h[i+j]));
                }
            }
        }

        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];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        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] - h[i+j]));
                }
            }
        }

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

} Main
import java.util.Arrays;
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];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        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] - h[i+j]));
                }
            }
        }

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

}