import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String str[] = reader.readLine().split(" ");
		
		int stoneCount= Integer.parseInt(str[0]);
		int maxJump = Integer.parseInt(str[1]);
		
		String str1[] = reader.readLine().split(" ");
		
	    int stones[] = new int[stoneCount];
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]);
	    
	    int dp[] = new int[stoneCount+1];
	    Arrays.fill(dp, Integer.MAX_VALUE);
	    dp[0] = 0;
	    for(int i=0;i<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    }
	    System.out.println(dp[stoneCount-1]);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String str[] = reader.readLine().split(" ");
		
		int stoneCount= Integer.parseInt(str[0]);
		int maxJump = Integer.parseInt(str[1]);
		
		String str1[] = reader.readLine().split(" ");
		
	    int stones[] = new int[stoneCount];
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]);
	    
	    int dp[] = new int[stoneCount+1];
	    Arrays.fill(dp, Integer.MAX_VALUE);
	    dp[0] = 0;
	    for(int i=0;i<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    }
	    System.out.println(dp[stoneCount-1]);
	}
} Main public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String str[] = reader.readLine().split(" ");
		
		int stoneCount= Integer.parseInt(str[0]);
		int maxJump = Integer.parseInt(str[1]);
		
		String str1[] = reader.readLine().split(" ");
		
	    int stones[] = new int[stoneCount];
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]);
	    
	    int dp[] = new int[stoneCount+1];
	    Arrays.fill(dp, Integer.MAX_VALUE);
	    dp[0] = 0;
	    for(int i=0;i<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    }
	    System.out.println(dp[stoneCount-1]);
	} main {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String str[] = reader.readLine().split(" ");
		
		int stoneCount= Integer.parseInt(str[0]);
		int maxJump = Integer.parseInt(str[1]);
		
		String str1[] = reader.readLine().split(" ");
		
	    int stones[] = new int[stoneCount];
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]);
	    
	    int dp[] = new int[stoneCount+1];
	    Arrays.fill(dp, Integer.MAX_VALUE);
	    dp[0] = 0;
	    for(int i=0;i<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    }
	    System.out.println(dp[stoneCount-1]);
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String str[] = reader.readLine().split(" "); str reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int stoneCount= Integer.parseInt(str[0]); stoneCount Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int maxJump = Integer.parseInt(str[1]); maxJump Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 String str1[] = reader.readLine().split(" "); str1 reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int stones[] = new int[stoneCount]; stones new int[stoneCount] stoneCount for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]); int i=0; int i=0; i 0 i<stoneCount i stoneCount i++ i++ i stones[i] = Integer.parseInt(str1[i]); stones[i] = Integer.parseInt(str1[i]) stones[i] stones i Integer.parseInt(str1[i]) Integer.parseInt Integer str1[i] str1 i int dp[] = new int[stoneCount+1]; dp new int[stoneCount+1] stoneCount+1 stoneCount 1 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<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    } int i=0; int i=0; i 0 i<stoneCount i stoneCount i++ i++ i {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    } {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    } for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	} int j=i+1; int j=i+1; j i+1 i 1 j<=i+maxJump j i+maxJump i maxJump j++ j++ j {
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	} {
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	} if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		} j<stoneCount j stoneCount {
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		} dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j])) dp[j] dp j Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j])) Math.min Math dp[j] dp j dp[i] + Math.abs(stones[i] - stones[j]) dp[i] dp i Math.abs(stones[i] - stones[j]) Math.abs Math stones[i] - stones[j] stones[i] stones i stones[j] stones j System.out.println(dp[stoneCount-1]) System.out.println System.out System System.out dp[stoneCount-1] dp stoneCount-1 stoneCount 1 String[] args args public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String str[] = reader.readLine().split(" ");
		
		int stoneCount= Integer.parseInt(str[0]);
		int maxJump = Integer.parseInt(str[1]);
		
		String str1[] = reader.readLine().split(" ");
		
	    int stones[] = new int[stoneCount];
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]);
	    
	    int dp[] = new int[stoneCount+1];
	    Arrays.fill(dp, Integer.MAX_VALUE);
	    dp[0] = 0;
	    for(int i=0;i<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    }
	    System.out.println(dp[stoneCount-1]);
	}
} public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String str[] = reader.readLine().split(" ");
		
		int stoneCount= Integer.parseInt(str[0]);
		int maxJump = Integer.parseInt(str[1]);
		
		String str1[] = reader.readLine().split(" ");
		
	    int stones[] = new int[stoneCount];
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]);
	    
	    int dp[] = new int[stoneCount+1];
	    Arrays.fill(dp, Integer.MAX_VALUE);
	    dp[0] = 0;
	    for(int i=0;i<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    }
	    System.out.println(dp[stoneCount-1]);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		String str[] = reader.readLine().split(" ");
		
		int stoneCount= Integer.parseInt(str[0]);
		int maxJump = Integer.parseInt(str[1]);
		
		String str1[] = reader.readLine().split(" ");
		
	    int stones[] = new int[stoneCount];
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str1[i]);
	    
	    int dp[] = new int[stoneCount+1];
	    Arrays.fill(dp, Integer.MAX_VALUE);
	    dp[0] = 0;
	    for(int i=0;i<stoneCount; i++)
	    {
	    	for(int j=i+1; j<=i+maxJump; j++)
	    	{
	    		if(j<stoneCount)
	    		{
	    			dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
	    		}
	    	}
	    }
	    System.out.println(dp[stoneCount-1]);
	}
}
