import java.util.Arrays;
import java.util.Scanner; // 文字列を標準入力からscanする

public class Main { 

  static long return_smaller(long a, long b){
    if(a > b){
      return b;
    }
      return a;
  }
    
  public static void main(final String[] args) {
    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    int N = Integer.parseInt(strs2[0]);
    int K = Integer.parseInt(strs2[1]);
    
    long[] hi = new long[N+K+1];
    long[] dp = new long[N+K+1];
    long oo = 1L << 60;
    Arrays.fill(dp, oo);

    str = scan.nextLine();
    String[] strs3 = str.split(" ");
    for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    }
    scan.close();

    int i = 0;
    int j = 0;

    dp[0] = 0;
    for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    }

    System.out.println(dp[N-1]);

  }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; // 文字列を標準入力からscanする Scanner java.util public class Main { 

  static long return_smaller(long a, long b){
    if(a > b){
      return b;
    }
      return a;
  }
    
  public static void main(final String[] args) {
    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    int N = Integer.parseInt(strs2[0]);
    int K = Integer.parseInt(strs2[1]);
    
    long[] hi = new long[N+K+1];
    long[] dp = new long[N+K+1];
    long oo = 1L << 60;
    Arrays.fill(dp, oo);

    str = scan.nextLine();
    String[] strs3 = str.split(" ");
    for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    }
    scan.close();

    int i = 0;
    int j = 0;

    dp[0] = 0;
    for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    }

    System.out.println(dp[N-1]);

  }
} Main static long return_smaller(long a, long b){
    if(a > b){
      return b;
    }
      return a;
  } return_smaller {
    if(a > b){
      return b;
    }
      return a;
  } if(a > b){
      return b;
    } a > b a b {
      return b;
    } return b; b return a; a long a a long b b public static void main(final String[] args) {
    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    int N = Integer.parseInt(strs2[0]);
    int K = Integer.parseInt(strs2[1]);
    
    long[] hi = new long[N+K+1];
    long[] dp = new long[N+K+1];
    long oo = 1L << 60;
    Arrays.fill(dp, oo);

    str = scan.nextLine();
    String[] strs3 = str.split(" ");
    for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    }
    scan.close();

    int i = 0;
    int j = 0;

    dp[0] = 0;
    for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    }

    System.out.println(dp[N-1]);

  } main {
    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    int N = Integer.parseInt(strs2[0]);
    int K = Integer.parseInt(strs2[1]);
    
    long[] hi = new long[N+K+1];
    long[] dp = new long[N+K+1];
    long oo = 1L << 60;
    Arrays.fill(dp, oo);

    str = scan.nextLine();
    String[] strs3 = str.split(" ");
    for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    }
    scan.close();

    int i = 0;
    int j = 0;

    dp[0] = 0;
    for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    }

    System.out.println(dp[N-1]);

  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String str = ""; str "" str = scan.nextLine() str scan.nextLine() scan.nextLine scan String[] strs2 = str.split(" "); strs2 str.split(" ") str.split str " " int N = Integer.parseInt(strs2[0]); N Integer.parseInt(strs2[0]) Integer.parseInt Integer strs2[0] strs2 0 int K = Integer.parseInt(strs2[1]); K Integer.parseInt(strs2[1]) Integer.parseInt Integer strs2[1] strs2 1 long[] hi = new long[N+K+1]; hi new long[N+K+1] N+K+1 N+K+1 N K 1 long[] dp = new long[N+K+1]; dp new long[N+K+1] N+K+1 N+K+1 N K 1 long oo = 1L << 60; oo 1L << 60 1L 60 Arrays.fill(dp, oo) Arrays.fill Arrays dp oo str = scan.nextLine() str scan.nextLine() scan.nextLine scan String[] strs3 = str.split(" "); strs3 str.split(" ") str.split str " " for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    } int i=0; int i=0; i 0 i<strs3.length i strs3.length strs3 strs3.length i++ i++ i {
      hi[i] = Integer.parseInt(strs3[i]);
    } {
      hi[i] = Integer.parseInt(strs3[i]);
    } hi[i] = Integer.parseInt(strs3[i]) hi[i] hi i Integer.parseInt(strs3[i]) Integer.parseInt Integer strs3[i] strs3 i scan.close() scan.close scan int i = 0; i 0 int j = 0; j 0 dp[0] = 0 dp[0] dp 0 0 for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    } i = 0; i = 0 i 0 i < N i N i++ i++ i {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    } {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    } for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      } j = 1; j = 1 j 1 j <= K j K j++ j++ j {
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      } {
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      } if(i-j < 0){
          break;
        } i-j < 0 i-j i j 0 {
          break;
        } break; dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j])) dp[i] dp i return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j])) return_smaller dp[i] dp i dp[i-j] + Math.abs(hi[i] - hi[i-j]) dp[i-j] dp i-j i j Math.abs(hi[i] - hi[i-j]) Math.abs Math hi[i] - hi[i-j] hi[i] hi i hi[i-j] hi i-j i j System.out.println(dp[N-1]) System.out.println System.out System System.out dp[N-1] dp N-1 N 1 final String[] args args public class Main { 

  static long return_smaller(long a, long b){
    if(a > b){
      return b;
    }
      return a;
  }
    
  public static void main(final String[] args) {
    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    int N = Integer.parseInt(strs2[0]);
    int K = Integer.parseInt(strs2[1]);
    
    long[] hi = new long[N+K+1];
    long[] dp = new long[N+K+1];
    long oo = 1L << 60;
    Arrays.fill(dp, oo);

    str = scan.nextLine();
    String[] strs3 = str.split(" ");
    for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    }
    scan.close();

    int i = 0;
    int j = 0;

    dp[0] = 0;
    for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    }

    System.out.println(dp[N-1]);

  }
} public class Main { 

  static long return_smaller(long a, long b){
    if(a > b){
      return b;
    }
      return a;
  }
    
  public static void main(final String[] args) {
    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    int N = Integer.parseInt(strs2[0]);
    int K = Integer.parseInt(strs2[1]);
    
    long[] hi = new long[N+K+1];
    long[] dp = new long[N+K+1];
    long oo = 1L << 60;
    Arrays.fill(dp, oo);

    str = scan.nextLine();
    String[] strs3 = str.split(" ");
    for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    }
    scan.close();

    int i = 0;
    int j = 0;

    dp[0] = 0;
    for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    }

    System.out.println(dp[N-1]);

  }
} Main
import java.util.Arrays;
import java.util.Scanner; // 文字列を標準入力からscanする

public class Main { 

  static long return_smaller(long a, long b){
    if(a > b){
      return b;
    }
      return a;
  }
    
  public static void main(final String[] args) {
    Scanner scan = new Scanner(System.in);
		String str = "";
    str = scan.nextLine();
    String[] strs2 = str.split(" ");
    int N = Integer.parseInt(strs2[0]);
    int K = Integer.parseInt(strs2[1]);
    
    long[] hi = new long[N+K+1];
    long[] dp = new long[N+K+1];
    long oo = 1L << 60;
    Arrays.fill(dp, oo);

    str = scan.nextLine();
    String[] strs3 = str.split(" ");
    for(int i=0; i<strs3.length; i++) {
      hi[i] = Integer.parseInt(strs3[i]);
    }
    scan.close();

    int i = 0;
    int j = 0;

    dp[0] = 0;
    for (i = 0; i < N; i++) {
      for(j = 1; j <= K; j++){
        if(i-j < 0){
          break;
        }
        dp[i] = return_smaller(dp[i], dp[i-j] + Math.abs(hi[i] - hi[i-j]));
      }
    }

    System.out.println(dp[N-1]);

  }
}