    import java.util.*;
     
    public class Main {
        public static void main(String[] args)  {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            int[] dp = new int[n];
            for(int i=0;i<n;i++)    h[i] = in.nextInt();
            for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            }
            solve(n, k, h, dp);
            System.out.println(dp[n-1]);
            in.close();
        }
     
        static void solve(int n, int k, int[] h, int[] dp) {
            for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            }
        }
    } import java.util.*; util.* java public class Main {
        public static void main(String[] args)  {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            int[] dp = new int[n];
            for(int i=0;i<n;i++)    h[i] = in.nextInt();
            for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            }
            solve(n, k, h, dp);
            System.out.println(dp[n-1]);
            in.close();
        }
     
        static void solve(int n, int k, int[] h, int[] dp) {
            for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            }
        }
    } Main public static void main(String[] args)  {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            int[] dp = new int[n];
            for(int i=0;i<n;i++)    h[i] = in.nextInt();
            for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            }
            solve(n, k, h, dp);
            System.out.println(dp[n-1]);
            in.close();
        } main {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            int[] dp = new int[n];
            for(int i=0;i<n;i++)    h[i] = in.nextInt();
            for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            }
            solve(n, k, h, dp);
            System.out.println(dp[n-1]);
            in.close();
        } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int k = in.nextInt(); k in.nextInt() in.nextInt in 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] = in.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i h[i] = in.nextInt(); h[i] = in.nextInt() h[i] h i in.nextInt() in.nextInt in for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            } int i=1; int i=1; i 1 i<=k && i<n i<=k i k i<n i n i++ i++ i {
                dp[i] = Math.abs(h[i] - h[0]);
            } {
                dp[i] = Math.abs(h[i] - h[0]);
            } dp[i] = Math.abs(h[i] - h[0]) dp[i] dp i Math.abs(h[i] - h[0]) Math.abs Math h[i] - h[0] h[i] h i h[0] h 0 solve(n, k, h, dp) solve n k h dp System.out.println(dp[n-1]) System.out.println System.out System System.out dp[n-1] dp n-1 n 1 in.close() in.close in String[] args args static void solve(int n, int k, int[] h, int[] dp) {
            for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            }
        } solve {
            for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            }
        } for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            } int i=k+1; int i=k+1; i k+1 k 1 i<n i n i++ i++ i {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            } {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            } int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int temp; temp for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                } {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                } temp = Math.abs(h[i]-h[i-j]) + dp[i-j] temp Math.abs(h[i]-h[i-j]) + dp[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 dp[i-j] dp i-j i j if(temp<min)    min = temp; temp<min temp min min = temp min temp dp[i] = min dp[i] dp i min int n n int k k int[] h h int[] dp dp public class Main {
        public static void main(String[] args)  {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            int[] dp = new int[n];
            for(int i=0;i<n;i++)    h[i] = in.nextInt();
            for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            }
            solve(n, k, h, dp);
            System.out.println(dp[n-1]);
            in.close();
        }
     
        static void solve(int n, int k, int[] h, int[] dp) {
            for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            }
        }
    } public class Main {
        public static void main(String[] args)  {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            int[] dp = new int[n];
            for(int i=0;i<n;i++)    h[i] = in.nextInt();
            for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            }
            solve(n, k, h, dp);
            System.out.println(dp[n-1]);
            in.close();
        }
     
        static void solve(int n, int k, int[] h, int[] dp) {
            for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            }
        }
    } Main
    import java.util.*;
     
    public class Main {
        public static void main(String[] args)  {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] h = new int[n];
            int[] dp = new int[n];
            for(int i=0;i<n;i++)    h[i] = in.nextInt();
            for(int i=1;i<=k && i<n;i++)   {
                dp[i] = Math.abs(h[i] - h[0]);
            }
            solve(n, k, h, dp);
            System.out.println(dp[n-1]);
            in.close();
        }
     
        static void solve(int n, int k, int[] h, int[] dp) {
            for(int i=k+1;i<n;i++)    {
                int min = Integer.MAX_VALUE;
                int temp;
                for(int j=1;j<=k;j++)    {
                    temp = Math.abs(h[i]-h[i-j]) + dp[i-j];
                    if(temp<min)    min = temp;
                }
                dp[i] = min;
            }
        }
    }