import java.util.*;
public class Main{
static long[] aa;
  static long maxx(int[] arr,int ind,int k){
  	if(ind==arr.length-1){
    	return 0;
    }
    if(aa[ind]!=-1){return aa[ind];}
    long maxs=Integer.MAX_VALUE;
    for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    }
    return aa[ind]=maxs;
  }
  
  public static void main(String[] args){
  
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    }
    aa=new long[n];
    Arrays.fill(aa,-1);
    System.out.println(maxx(arr,0,k));
  
  }
  
} import java.util.*; util.* java public class Main{
static long[] aa;
  static long maxx(int[] arr,int ind,int k){
  	if(ind==arr.length-1){
    	return 0;
    }
    if(aa[ind]!=-1){return aa[ind];}
    long maxs=Integer.MAX_VALUE;
    for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    }
    return aa[ind]=maxs;
  }
  
  public static void main(String[] args){
  
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    }
    aa=new long[n];
    Arrays.fill(aa,-1);
    System.out.println(maxx(arr,0,k));
  
  }
  
} Main static long[] aa; aa static long maxx(int[] arr,int ind,int k){
  	if(ind==arr.length-1){
    	return 0;
    }
    if(aa[ind]!=-1){return aa[ind];}
    long maxs=Integer.MAX_VALUE;
    for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    }
    return aa[ind]=maxs;
  } maxx {
  	if(ind==arr.length-1){
    	return 0;
    }
    if(aa[ind]!=-1){return aa[ind];}
    long maxs=Integer.MAX_VALUE;
    for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    }
    return aa[ind]=maxs;
  } if(ind==arr.length-1){
    	return 0;
    } ind==arr.length-1 ind arr.length-1 arr.length arr arr.length 1 {
    	return 0;
    } return 0; 0 if(aa[ind]!=-1){return aa[ind];} aa[ind]!=-1 aa[ind] aa ind -1 1 {return aa[ind];} return aa[ind]; aa[ind] aa ind long maxs=Integer.MAX_VALUE; maxs Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    } {
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    } if(ind+j>=arr.length){break;} ind+j>=arr.length ind+j ind j arr.length arr arr.length {break;} break; maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  ) maxs (long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  ) Math.min Math maxs maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] ) maxx(arr,ind+j,k ) maxx arr ind+j ind j k (long)Math.abs(arr[ind]-arr[ind+j] ) Math.abs Math arr[ind]-arr[ind+j] arr[ind] arr ind arr[ind+j] arr ind+j ind j return aa[ind]=maxs; aa[ind]=maxs aa[ind] aa ind maxs int[] arr arr int ind ind int k k public static void main(String[] args){
  
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    }
    aa=new long[n];
    Arrays.fill(aa,-1);
    System.out.println(maxx(arr,0,k));
  
  } main {
  
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    }
    aa=new long[n];
    Arrays.fill(aa,-1);
    System.out.println(maxx(arr,0,k));
  
  } Scanner s=new Scanner(System.in); s new Scanner(System.in) int n=s.nextInt(); n s.nextInt() s.nextInt s int k=s.nextInt(); k s.nextInt() s.nextInt s int[] arr=new int[n]; arr new int[n] n for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    } int j=0; int j=0; j 0 j<n j n j++ j++ j {
    	arr[j]=s.nextInt();
    } {
    	arr[j]=s.nextInt();
    } arr[j]=s.nextInt() arr[j] arr j s.nextInt() s.nextInt s aa=new long[n] aa new long[n] n Arrays.fill(aa,-1) Arrays.fill Arrays aa -1 1 System.out.println(maxx(arr,0,k)) System.out.println System.out System System.out maxx(arr,0,k) maxx arr 0 k String[] args args public class Main{
static long[] aa;
  static long maxx(int[] arr,int ind,int k){
  	if(ind==arr.length-1){
    	return 0;
    }
    if(aa[ind]!=-1){return aa[ind];}
    long maxs=Integer.MAX_VALUE;
    for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    }
    return aa[ind]=maxs;
  }
  
  public static void main(String[] args){
  
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    }
    aa=new long[n];
    Arrays.fill(aa,-1);
    System.out.println(maxx(arr,0,k));
  
  }
  
} public class Main{
static long[] aa;
  static long maxx(int[] arr,int ind,int k){
  	if(ind==arr.length-1){
    	return 0;
    }
    if(aa[ind]!=-1){return aa[ind];}
    long maxs=Integer.MAX_VALUE;
    for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    }
    return aa[ind]=maxs;
  }
  
  public static void main(String[] args){
  
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    }
    aa=new long[n];
    Arrays.fill(aa,-1);
    System.out.println(maxx(arr,0,k));
  
  }
  
} Main
import java.util.*;
public class Main{
static long[] aa;
  static long maxx(int[] arr,int ind,int k){
  	if(ind==arr.length-1){
    	return 0;
    }
    if(aa[ind]!=-1){return aa[ind];}
    long maxs=Integer.MAX_VALUE;
    for(int j=1;j<=k;j++){
      if(ind+j>=arr.length){break;}
    	maxs=(long)Math.min( maxs, maxx(arr,ind+j,k )+(long)Math.abs(arr[ind]-arr[ind+j] )  );
    }
    return aa[ind]=maxs;
  }
  
  public static void main(String[] args){
  
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int k=s.nextInt();
    int[] arr=new int[n];
    for(int j=0;j<n;j++){
    	arr[j]=s.nextInt();
    }
    aa=new long[n];
    Arrays.fill(aa,-1);
    System.out.println(maxx(arr,0,k));
  
  }
  
}