import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

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

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

        System.out.println(dp[n-1]);
    }
} import java.io.IOException; IOException java.io import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws IOException {


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

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

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

        System.out.println(dp[n-1]);
    }
} Main public static void main(String[] args) throws IOException {


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

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

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

        System.out.println(dp[n-1]);
    } main {


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

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

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

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


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

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

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

        System.out.println(dp[n-1]);
    }
} public class Main {

    public static void main(String[] args) throws IOException {


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

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

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

        System.out.println(dp[n-1]);
    }
} Main
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {


       // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int arr[] = new int[n];

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

        int dp[] = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        for(int i=0;i<n;i++) {
          for(int j=(i+1);j<=(i+k);j++) {
              if(j<n) {
                  dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[i]-arr[j]));
              }
          }
        }

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