/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int k){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int k){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	}
} Main public static int minCost(int []h , int curr_ind , int n , int []dp , int k){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    } minCost {
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    } if(curr_ind > n-1  )
	        return 0; curr_ind > n-1 curr_ind n-1 n 1 return 0; 0 if(dp[curr_ind]!=-1) return dp[curr_ind]; dp[curr_ind]!=-1 dp[curr_ind] dp curr_ind -1 1 return dp[curr_ind]; dp[curr_ind] dp curr_ind int a = Integer.MAX_VALUE; a Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        } int i = curr_ind + 1; int i = curr_ind + 1; i curr_ind + 1 curr_ind 1 i<=Math.min(n,curr_ind+k) i Math.min(n,curr_ind+k) Math.min Math n curr_ind+k curr_ind k i++ i++ i {
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        } {
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        } a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) a Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) Math.min Math a (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k)) Math.abs(h[curr_ind] - h[i]) Math.abs Math h[curr_ind] - h[i] h[curr_ind] h curr_ind h[i] h i minCost(h , i , n ,dp , k) minCost h i n dp k return dp[curr_ind] = a; dp[curr_ind] = a dp[curr_ind] dp curr_ind a int []h h int curr_ind curr_ind int n n int []dp dp int k k public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	} main {
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	} Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in))); sc new Scanner(new BufferedReader(new InputStreamReader(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+1]; h new int[n+1] n+1 n 1 for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			} int i =1; int i =1; i 1 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+1]; dp new int[n+1] n+1 n 1 for(int j =0;j<n+1;j++)
			dp[j] = -1; int j =0; int j =0; j 0 j<n+1 j n+1 n 1 j++ j++ j dp[j] = -1; dp[j] = -1 dp[j] dp j -1 1 System.out.println(minCost(h , 1 , n , dp , k)) System.out.println System.out System System.out minCost(h , 1 , n , dp , k) minCost h 1 n dp k String[] args args public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int k){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	}
} public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int k){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	}
} Main
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int k){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	}
}
