import java.util.*;
class Main{
   static Integer[]cache;
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int []x=new int[n];
    cache=new Integer[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    }
    System.out.println(ans1(x,0,k));
  }
 
    public static int ans1(int []h,int index,int k){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int current=Integer.MAX_VALUE;
        for(int i=1;i<=k;i++){
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        }
 
        return cache[index]=current;
    }
 
} import java.util.*; util.* java class Main{
   static Integer[]cache;
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int []x=new int[n];
    cache=new Integer[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    }
    System.out.println(ans1(x,0,k));
  }
 
    public static int ans1(int []h,int index,int k){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int current=Integer.MAX_VALUE;
        for(int i=1;i<=k;i++){
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        }
 
        return cache[index]=current;
    }
 
} Main static Integer[]cache; cache public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int []x=new int[n];
    cache=new Integer[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    }
    System.out.println(ans1(x,0,k));
  } main {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int []x=new int[n];
    cache=new Integer[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    }
    System.out.println(ans1(x,0,k));
  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int k=sc.nextInt(); k sc.nextInt() sc.nextInt sc int []x=new int[n]; x new int[n] n cache=new Integer[n] cache new Integer[n] n for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      x[i]=sc.nextInt();
    } {
      x[i]=sc.nextInt();
    } x[i]=sc.nextInt() x[i] x i sc.nextInt() sc.nextInt sc System.out.println(ans1(x,0,k)) System.out.println System.out System System.out ans1(x,0,k) ans1 x 0 k String[] args args public static int ans1(int []h,int index,int k){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int current=Integer.MAX_VALUE;
        for(int i=1;i<=k;i++){
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        }
 
        return cache[index]=current;
    } ans1 {
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int current=Integer.MAX_VALUE;
        for(int i=1;i<=k;i++){
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        }
 
        return cache[index]=current;
    } if(index==h.length-1) return 0; index==h.length-1 index h.length-1 h.length h h.length 1 return 0; 0 if(cache[index]!=null) return cache[index]; cache[index]!=null cache[index] cache index null return cache[index]; cache[index] cache index int current=Integer.MAX_VALUE; current Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i=1;i<=k;i++){
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        } {
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        } if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            } index+i<h.length index+i index i h.length h h.length {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            } current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k)) current Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k)) Math.min Math current Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k) Math.abs(h[index] - h[index + i]) Math.abs Math h[index] - h[index + i] h[index] h index h[index + i] h index + i index i ans1(h, index + i, k) ans1 h index + i index i k return cache[index]=current; cache[index]=current cache[index] cache index current int []h h int index index int k k
import java.util.*;
class Main{
   static Integer[]cache;
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int []x=new int[n];
    cache=new Integer[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    }
    System.out.println(ans1(x,0,k));
  }
 
    public static int ans1(int []h,int index,int k){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int current=Integer.MAX_VALUE;
        for(int i=1;i<=k;i++){
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        }
 
        return cache[index]=current;
    }
 
}