import java.util.*;


import java.io.*;



public class Main 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	}
} Main static int dp[]; dp public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	} main { 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	} 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 ar[]=new int[n]; ar new int[n] n for(int i=0;i<n;i++)
			ar[i]=s.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i ar[i]=s.nextInt(); ar[i]=s.nextInt() ar[i] ar i s.nextInt() s.nextInt s 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(ar[1]-ar[0]) dp[1] dp 1 Math.abs(ar[1]-ar[0]) Math.abs Math ar[1]-ar[0] ar[1] ar 1 ar[0] ar 0 for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		} int i=2; int i=2; i 2 i<n i n i++ i++ i {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		} {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		} for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			} {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			} if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j])); i-j>=0 i-j i j 0 dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j])) dp[i] dp i Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j])) Math.min Math dp[i] dp i dp[i-j]+Math.abs(ar[i]-ar[i-j]) dp[i-j] dp i-j i j Math.abs(ar[i]-ar[i-j]) Math.abs Math ar[i]-ar[i-j] ar[i] ar i ar[i-j] ar i-j i j 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 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	}
} public class Main 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	}
} Main
import java.util.*;


import java.io.*;



public class Main 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				if(i-j>=0)
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	}
}