import java.io.*;
import java.util.*;
public class Main{
	static int n,k;
	static int[] height=new int[100001];
	public static int solve(){
		int[] dp=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		}
		return dp[n-1];
	}
	public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String[] str=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		k=Integer.parseInt(str[1]); 		
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		}
		System.out.println(solve());
	
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
	static int n,k;
	static int[] height=new int[100001];
	public static int solve(){
		int[] dp=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		}
		return dp[n-1];
	}
	public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String[] str=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		k=Integer.parseInt(str[1]); 		
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		}
		System.out.println(solve());
	
    }
} Main static int n n k; k static int[] height=new int[100001]; height new int[100001] 100001 public static int solve(){
		int[] dp=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		}
		return dp[n-1];
	} solve {
		int[] dp=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		}
		return dp[n-1];
	} int[] dp=new int[n]; dp new int[n] n dp[0]=0 dp[0] dp 0 0 for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		} {
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		} dp[i]=Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			} int j=i-1; int j=i-1; j i-1 i 1 j>=Math.max(0,i-k) j Math.max(0,i-k) Math.max Math 0 i-k i k j-- j-- j {
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			} {
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			} dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j])) dp[i] dp i Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j])) Math.min Math dp[i] dp i dp[j]+Math.abs(height[i]-height[j]) dp[j] dp j Math.abs(height[i]-height[j]) Math.abs Math height[i]-height[j] height[i] height i height[j] height j return dp[n-1]; dp[n-1] dp n-1 n 1 public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String[] str=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		k=Integer.parseInt(str[1]); 		
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		}
		System.out.println(solve());
	
    } main {
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String[] str=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		k=Integer.parseInt(str[1]); 		
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		}
		System.out.println(solve());
	
    } BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); br new BufferedReader( 
                              new InputStreamReader(System.in)) String[] str=br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n=Integer.parseInt(str[0]) n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 k=Integer.parseInt(str[1]) k Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 str=br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {			
		   height[i]=Integer.parseInt(str[i]);		 
		} {			
		   height[i]=Integer.parseInt(str[i]);		 
		} height[i]=Integer.parseInt(str[i]) height[i] height i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i System.out.println(solve()) System.out.println System.out System System.out solve() solve String[] args args public class Main{
	static int n,k;
	static int[] height=new int[100001];
	public static int solve(){
		int[] dp=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		}
		return dp[n-1];
	}
	public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String[] str=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		k=Integer.parseInt(str[1]); 		
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		}
		System.out.println(solve());
	
    }
} public class Main{
	static int n,k;
	static int[] height=new int[100001];
	public static int solve(){
		int[] dp=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		}
		return dp[n-1];
	}
	public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String[] str=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		k=Integer.parseInt(str[1]); 		
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		}
		System.out.println(solve());
	
    }
} Main
import java.io.*;
import java.util.*;
public class Main{
	static int n,k;
	static int[] height=new int[100001];
	public static int solve(){
		int[] dp=new int[n];
		dp[0]=0;
		for(int i=1;i<n;i++){
			dp[i]=Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--){
				dp[i]=Math.min(dp[i],dp[j]+Math.abs(height[i]-height[j]));
			}
			
		}
		return dp[n-1];
	}
	public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String[] str=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		k=Integer.parseInt(str[1]); 		
		str=br.readLine().split(" ");
		for(int i=0;i<n;i++){			
		   height[i]=Integer.parseInt(str[i]);		 
		}
		System.out.println(solve());
	
    }
}