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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
     	int n = Integer.parseInt(st.nextToken());
     	int k = Integer.parseInt(st.nextToken());
     	int ar[] = new int[n];
   		int dp[] = new int[n];
   		st = new StringTokenizer(br.readLine());
       	for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
       
       	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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	}
       	
       	System.out.println(dp[n-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.StringTokenizer; StringTokenizer java.util public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
     	int n = Integer.parseInt(st.nextToken());
     	int k = Integer.parseInt(st.nextToken());
     	int ar[] = new int[n];
   		int dp[] = new int[n];
   		st = new StringTokenizer(br.readLine());
       	for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
       
       	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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	}
       	
       	System.out.println(dp[n-1]);
     
       
	}
} Main public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
     	int n = Integer.parseInt(st.nextToken());
     	int k = Integer.parseInt(st.nextToken());
     	int ar[] = new int[n];
   		int dp[] = new int[n];
   		st = new StringTokenizer(br.readLine());
       	for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
       
       	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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	}
       	
       	System.out.println(dp[n-1]);
     
       
	} main {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
     	int n = Integer.parseInt(st.nextToken());
     	int k = Integer.parseInt(st.nextToken());
     	int ar[] = new int[n];
   		int dp[] = new int[n];
   		st = new StringTokenizer(br.readLine());
       	for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
       
       	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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	}
       	
       	System.out.println(dp[n-1]);
     
       
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int n = Integer.parseInt(st.nextToken()); n Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int k = Integer.parseInt(st.nextToken()); k Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int ar[] = new int[n]; ar new int[n] n int dp[] = new int[n]; dp new int[n] n st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	} int i =0; int i =0; i 0 i<n i n i++ i++ i {
       		ar[i] = Integer.parseInt(st.nextToken());
       	} {
       		ar[i] = Integer.parseInt(st.nextToken());
       	} ar[i] = Integer.parseInt(st.nextToken()) ar[i] ar i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st 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] , Math.abs(ar[i] - ar[j]) + dp[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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	} {
       		dp[i] = Integer.MAX_VALUE;
       		for(int j = i-1; j>=Math.max(0, i-k); j--)
       			dp[i] = Math.min(dp[i] , Math.abs(ar[i] - ar[j]) + dp[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] , Math.abs(ar[i] - ar[j]) + dp[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] , Math.abs(ar[i] - ar[j]) + dp[j]); dp[i] = Math.min(dp[i] , Math.abs(ar[i] - ar[j]) + dp[j]) dp[i] dp i Math.min(dp[i] , Math.abs(ar[i] - ar[j]) + dp[j]) Math.min Math dp[i] dp i Math.abs(ar[i] - ar[j]) + dp[j] Math.abs(ar[i] - ar[j]) Math.abs Math ar[i] - ar[j] ar[i] ar i ar[j] ar j dp[j] dp 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 {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
     	int n = Integer.parseInt(st.nextToken());
     	int k = Integer.parseInt(st.nextToken());
     	int ar[] = new int[n];
   		int dp[] = new int[n];
   		st = new StringTokenizer(br.readLine());
       	for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
       
       	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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	}
       	
       	System.out.println(dp[n-1]);
     
       
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
     	int n = Integer.parseInt(st.nextToken());
     	int k = Integer.parseInt(st.nextToken());
     	int ar[] = new int[n];
   		int dp[] = new int[n];
   		st = new StringTokenizer(br.readLine());
       	for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
       
       	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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	}
       	
       	System.out.println(dp[n-1]);
     
       
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
     	int n = Integer.parseInt(st.nextToken());
     	int k = Integer.parseInt(st.nextToken());
     	int ar[] = new int[n];
   		int dp[] = new int[n];
   		st = new StringTokenizer(br.readLine());
       	for(int i =0;i<n;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
       
       	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] , Math.abs(ar[i] - ar[j]) + dp[j]);
       	}
       	
       	System.out.println(dp[n-1]);
     
       
	}
}