import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k=s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n];
        
        for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        }
      
        System.out.println(dp[0]);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k=s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n];
        
        for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        }
      
        System.out.println(dp[0]);
    }
} Main public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k=s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n];
        
        for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        }
      
        System.out.println(dp[0]);
    } main {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k=s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n];
        
        for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        }
      
        System.out.println(dp[0]);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int k=s.nextInt(); k s.nextInt() s.nextInt s int[] arr = new int[n]; arr new int[n] n for(int i=0;i<n;i++)
        	arr[i]=s.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i]=s.nextInt(); arr[i]=s.nextInt() arr[i] arr i s.nextInt() s.nextInt s int[] dp = new int[n]; dp new int[n] n for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        } int i = n - 2; int i = n - 2; i n - 2 n 2 i >= 0 i 0 i-- i-- i {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        } {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        } int bop=Integer.MAX_VALUE; bop Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            } int j=1; int j=1; j 1 j<=k&&i+j<n j<=k j k i+j<n i+j i j n j++ j++ j {
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            } {
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            } int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i]; cop Math.abs(arr[i]-arr[i+j])+dp[j+i] Math.abs(arr[i]-arr[i+j]) Math.abs Math arr[i]-arr[i+j] arr[i] arr i arr[i+j] arr i+j i j dp[j+i] dp j+i j i bop=Math.min(bop,cop) bop Math.min(bop,cop) Math.min Math bop cop dp[i]=bop dp[i] dp i bop System.out.println(dp[0]) System.out.println System.out System System.out dp[0] dp 0 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k=s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n];
        
        for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        }
      
        System.out.println(dp[0]);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k=s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n];
        
        for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        }
      
        System.out.println(dp[0]);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k=s.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();
      
        int[] dp = new int[n];
        
        for (int i = n - 2; i >= 0; i--) {
            int bop=Integer.MAX_VALUE;

            for(int j=1;j<=k&&i+j<n;j++){
                int cop=Math.abs(arr[i]-arr[i+j])+dp[j+i];
                bop=Math.min(bop,cop);
            }

            dp[i]=bop;

            
        }
      
        System.out.println(dp[0]);
    }
}