import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int[] DP = new int[n];
    Arrays.fill(DP,Integer.MAX_VALUE);

    for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    }

    DP[0] = 0;
    DP[1] = Math.abs(h[1] -h[0]);

    for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    }

    System.out.println(DP[n-1]);

  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int[] DP = new int[n];
    Arrays.fill(DP,Integer.MAX_VALUE);

    for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    }

    DP[0] = 0;
    DP[1] = Math.abs(h[1] -h[0]);

    for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    }

    System.out.println(DP[n-1]);

  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int[] DP = new int[n];
    Arrays.fill(DP,Integer.MAX_VALUE);

    for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    }

    DP[0] = 0;
    DP[1] = Math.abs(h[1] -h[0]);

    for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    }

    System.out.println(DP[n-1]);

  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int[] DP = new int[n];
    Arrays.fill(DP,Integer.MAX_VALUE);

    for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    }

    DP[0] = 0;
    DP[1] = Math.abs(h[1] -h[0]);

    for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    }

    System.out.println(DP[n-1]);

  } 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[] h = new int[n]; h new int[n] n int[] DP = new int[n]; DP new int[n] n Arrays.fill(DP,Integer.MAX_VALUE) Arrays.fill Arrays DP Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      h[i] = sc.nextInt();
    } {
      h[i] = sc.nextInt();
    } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc DP[0] = 0 DP[0] DP 0 0 DP[1] = Math.abs(h[1] -h[0]) DP[1] DP 1 Math.abs(h[1] -h[0]) Math.abs Math h[1] -h[0] h[1] h 1 h[0] h 0 for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    } int i=2; int i=2; i 2 i<n i n i++ i++ i {
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    } {
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    } for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      } {
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      } DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j])) DP[i] DP i Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j])) Math.min Math DP[i] DP i DP[i-j]+Math.abs(h[i]-h[i-j]) DP[i-j] DP i-j i j Math.abs(h[i]-h[i-j]) Math.abs Math h[i]-h[i-j] h[i] h i h[i-j] h i-j i j if(i-j==0){break;} i-j==0 i-j i j 0 {break;} break; 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){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int[] DP = new int[n];
    Arrays.fill(DP,Integer.MAX_VALUE);

    for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    }

    DP[0] = 0;
    DP[1] = Math.abs(h[1] -h[0]);

    for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    }

    System.out.println(DP[n-1]);

  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int[] DP = new int[n];
    Arrays.fill(DP,Integer.MAX_VALUE);

    for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    }

    DP[0] = 0;
    DP[1] = Math.abs(h[1] -h[0]);

    for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    }

    System.out.println(DP[n-1]);

  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] h = new int[n];
    int[] DP = new int[n];
    Arrays.fill(DP,Integer.MAX_VALUE);

    for(int i=0; i<n; i++){
      h[i] = sc.nextInt();
    }

    DP[0] = 0;
    DP[1] = Math.abs(h[1] -h[0]);

    for(int i=2; i<n; i++){
      for(int j=1; j<=k;j++){
        DP[i] = Math.min(DP[i],DP[i-j]+Math.abs(h[i]-h[i-j]));
        if(i-j==0){break;}
      }

    }

    System.out.println(DP[n-1]);

  }
}