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

public class Main {
  public static void main(String[] args) {
	Scanner scn =new Scanner(System.in);
	int n = scn.nextInt();
	int k = scn.nextInt();
	int[]h = new int[n];
	for(int i=0;i<n;i++)
	{
		h[i]=scn.nextInt();
	}
	int[]dp=new int[n];
	Arrays.fill(dp, Integer.MAX_VALUE);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	}
	System.out.println(dp[n-1]);
}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
	Scanner scn =new Scanner(System.in);
	int n = scn.nextInt();
	int k = scn.nextInt();
	int[]h = new int[n];
	for(int i=0;i<n;i++)
	{
		h[i]=scn.nextInt();
	}
	int[]dp=new int[n];
	Arrays.fill(dp, Integer.MAX_VALUE);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	}
	System.out.println(dp[n-1]);
}
} Main public static void main(String[] args) {
	Scanner scn =new Scanner(System.in);
	int n = scn.nextInt();
	int k = scn.nextInt();
	int[]h = new int[n];
	for(int i=0;i<n;i++)
	{
		h[i]=scn.nextInt();
	}
	int[]dp=new int[n];
	Arrays.fill(dp, Integer.MAX_VALUE);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	}
	System.out.println(dp[n-1]);
} main {
	Scanner scn =new Scanner(System.in);
	int n = scn.nextInt();
	int k = scn.nextInt();
	int[]h = new int[n];
	for(int i=0;i<n;i++)
	{
		h[i]=scn.nextInt();
	}
	int[]dp=new int[n];
	Arrays.fill(dp, Integer.MAX_VALUE);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	}
	System.out.println(dp[n-1]);
} Scanner scn =new Scanner(System.in); scn new Scanner(System.in) int n = scn.nextInt(); n scn.nextInt() scn.nextInt scn int k = scn.nextInt(); k scn.nextInt() scn.nextInt scn int[]h = new int[n]; h new int[n] n for(int i=0;i<n;i++)
	{
		h[i]=scn.nextInt();
	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
		h[i]=scn.nextInt();
	} {
		h[i]=scn.nextInt();
	} h[i]=scn.nextInt() h[i] h i scn.nextInt() scn.nextInt scn 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 for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	} {
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	} for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		} int j=i+1; int j=i+1; j i+1 i 1 j<=i+k j i+k i k j++ j++ j {
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		} {
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		} if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			} j<n&&dp[i]!=Integer.MAX_VALUE j<n j n dp[i]!=Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE {
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			} dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]) dp[j] dp j Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]) Math.min Math dp[j] dp j Math.abs(h[j]-h[i])+dp[i] Math.abs(h[j]-h[i]) Math.abs Math h[j]-h[i] h[j] h j h[i] h i dp[i] dp i 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 {
  public static void main(String[] args) {
	Scanner scn =new Scanner(System.in);
	int n = scn.nextInt();
	int k = scn.nextInt();
	int[]h = new int[n];
	for(int i=0;i<n;i++)
	{
		h[i]=scn.nextInt();
	}
	int[]dp=new int[n];
	Arrays.fill(dp, Integer.MAX_VALUE);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	}
	System.out.println(dp[n-1]);
}
} public class Main {
  public static void main(String[] args) {
	Scanner scn =new Scanner(System.in);
	int n = scn.nextInt();
	int k = scn.nextInt();
	int[]h = new int[n];
	for(int i=0;i<n;i++)
	{
		h[i]=scn.nextInt();
	}
	int[]dp=new int[n];
	Arrays.fill(dp, Integer.MAX_VALUE);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n&&dp[i]!=Integer.MAX_VALUE)
			{
				dp[j]=Math.min(dp[j], Math.abs(h[j]-h[i])+dp[i]);
			}
		}
	}
	System.out.println(dp[n-1]);
}
} Main
import java.util.Arrays;
import java.util.Scanner;

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