import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static int n,k;
	//public static int count;
	public static int[] arr,dp;
	public static int frog2(int pos)
	{
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	}

} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	public static int n,k;
	//public static int count;
	public static int[] arr,dp;
	public static int frog2(int pos)
	{
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	}

} Main public static int n n k; k //public static int count;
	public static int[] arr arr dp; dp public static int frog2(int pos)
	{
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	} frog2 {
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	} if(pos>=n-1)
			return 0; pos>=n-1 pos n-1 n 1 return 0; 0 if(dp[pos]!=-1)
			return dp[pos]; dp[pos]!=-1 dp[pos] dp pos -1 1 return dp[pos]; dp[pos] dp pos int cost=Integer.MAX_VALUE; cost Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			} int i=1; int i=1; i 1 i<=k i k i++ i++ i if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			} if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			} pos+i<n pos+i pos i n { cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			} cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i)) cost Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i)) Math.min Math cost Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i) Math.abs(arr[pos]-arr[pos+i]) Math.abs Math arr[pos]-arr[pos+i] arr[pos] arr pos arr[pos+i] arr pos+i pos i frog2(pos+i) frog2 pos+i pos i return dp[pos]=cost; dp[pos]=cost dp[pos] dp pos cost int pos pos public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	} main {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	} Scanner in=new Scanner(System.in); in new Scanner(System.in) n=in.nextInt() n in.nextInt() in.nextInt in k=in.nextInt() k in.nextInt() in.nextInt in arr=new int[n] arr new int[n] n dp=new int[n] dp new int[n] n for(int i=0;i<n;i++)
			arr[i]=in.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i]=in.nextInt(); arr[i]=in.nextInt() arr[i] arr i in.nextInt() in.nextInt in Arrays.fill(dp,-1) Arrays.fill Arrays dp -1 1 System.out.println(frog2(0)) System.out.println System.out System System.out frog2(0) frog2 0 String[] args args public class Main {
	public static int n,k;
	//public static int count;
	public static int[] arr,dp;
	public static int frog2(int pos)
	{
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	}

} public class Main {
	public static int n,k;
	//public static int count;
	public static int[] arr,dp;
	public static int frog2(int pos)
	{
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static int n,k;
	//public static int count;
	public static int[] arr,dp;
	public static int frog2(int pos)
	{
		if(pos>=n-1)
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int cost=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
			if(pos+i<n)
			{ cost=Math.min(cost, Math.abs(arr[pos]-arr[pos+i])+frog2(pos+i));
			  //System.out.println((count++)+" "+pos+" "+i+" "+cost);
			}
		return dp[pos]=cost;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		k=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(frog2(0));
	
	}

}
