import java.util.*;
 
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int k = sc.nextInt();
      
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;

      for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      }
      System.out.println(dp[dp.length-1]);
    }
  
} import java.util.*; util.* java public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int k = sc.nextInt();
      
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;

      for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      }
      System.out.println(dp[dp.length-1]);
    }
  
} Main public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int k = sc.nextInt();
      
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;

      for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      }
      System.out.println(dp[dp.length-1]);
    } main {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int k = sc.nextInt();
      
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;

      for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      }
      System.out.println(dp[dp.length-1]);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int t = sc.nextInt(); t sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc int[] arr = new int[t]; arr new int[t] t for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      } int i =0; int i =0; i 0 i<t i t i++ i++ i {
        arr[i]= sc.nextInt();
      } {
        arr[i]= sc.nextInt();
      } arr[i]= sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int[] dp = new int[t]; dp new int[t] t dp[0] = 0 dp[0] dp 0 0 for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      } int i =1; int i =1; i 1 i<t i t i++ i++ i {
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      } {
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      } int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        } int j =1; int j =1; j 1 j<=k j k j++ j++ j {
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        } {
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        } if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          } i-j>=0 i-j i j 0 {
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          } min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min) min Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min) Math.min Math dp[i-j]+ Math.abs(arr[i]-arr[i-j]) dp[i-j] dp i-j i j Math.abs(arr[i]-arr[i-j]) Math.abs Math arr[i]-arr[i-j] arr[i] arr i arr[i-j] arr i-j i j min dp[i]= min dp[i] dp i min System.out.println(dp[dp.length-1]) System.out.println System.out System System.out dp[dp.length-1] dp dp.length-1 dp.length dp dp.length 1 String[] args args public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int k = sc.nextInt();
      
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;

      for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      }
      System.out.println(dp[dp.length-1]);
    }
  
} public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int k = sc.nextInt();
      
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;

      for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      }
      System.out.println(dp[dp.length-1]);
    }
  
} Main
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int k = sc.nextInt();
      
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;

      for(int i =1;i<t;i++){
        int min = Integer.MAX_VALUE;
        for(int j =1;j<=k;j++){
          if(i-j>=0){
            min = Math.min(dp[i-j]+ Math.abs(arr[i]-arr[i-j]),min);
          }
        }
        dp[i]= min;
      }
      System.out.println(dp[dp.length-1]);
    }
  
}
