import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        }
        System.out.println(dp[n - 1]);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        }
        System.out.println(dp[n - 1]);
    }
} Main public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        }
        System.out.println(dp[n - 1]);
    } main {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        }
        System.out.println(dp[n - 1]);
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int k = input.nextInt(); k input.nextInt() input.nextInt input int[] nums = new int[n]; nums new int[n] n for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            nums[i] = input.nextInt();
        } {
            nums[i] = input.nextInt();
        } nums[i] = input.nextInt() nums[i] nums i input.nextInt() input.nextInt input int[] dp = new int[n]; dp new int[n] n Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0] = 0 dp[0] dp 0 0 dp[1] = Math.abs(nums[1] - nums[0]) dp[1] dp 1 Math.abs(nums[1] - nums[0]) Math.abs Math nums[1] - nums[0] nums[1] nums 1 nums[0] nums 0 for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        } int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        } {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        } for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            } int h = k; int h = k; h k h >= 1 h 1 h-- h-- h {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            } {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            } try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                } catch(Exception e) {

                } Exception e {

                } {
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h])) dp[i] dp i Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h])) Math.min Math dp[i] dp i dp[i - h] + Math.abs(nums[i] - nums[i - h]) dp[i - h] dp i - h i h Math.abs(nums[i] - nums[i - h]) Math.abs Math nums[i] - nums[i - h] nums[i] nums i nums[i - h] nums i - h i h 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 input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        }
        System.out.println(dp[n - 1]);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        }
        System.out.println(dp[n - 1]);
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

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