import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
      	int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        }
        output.println(dp[N-1]);
      	output.close();
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
      	int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        }
        output.println(dp[N-1]);
      	output.close();
    }
} Main public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
      	int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        }
        output.println(dp[N-1]);
      	output.close();
    } main {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
      	int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        }
        output.println(dp[N-1]);
      	output.close();
    } BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); input new BufferedReader(new InputStreamReader(System.in)) PrintWriter output = new PrintWriter(System.out); output new PrintWriter(System.out) StringTokenizer st = new StringTokenizer(input.readLine()); st new StringTokenizer(input.readLine()) int N = Integer.parseInt(st.nextToken()); N Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int K = Integer.parseInt(st.nextToken()); K Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st st = new StringTokenizer(input.readLine()) st new StringTokenizer(input.readLine()) int[] arr = new int[N]; arr new int[N] N int[] dp = new int[N+1]; dp new int[N+1] N+1 N 1 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++){
            arr[i] = Integer.parseInt(st.nextToken());
        } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
            arr[i] = Integer.parseInt(st.nextToken());
        } {
            arr[i] = Integer.parseInt(st.nextToken());
        } arr[i] = Integer.parseInt(st.nextToken()) arr[i] arr i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        } {
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        } for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          } int k = 1; int k = 1; k 1 k<K+1 k K+1 K 1 k++ k++ k {
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          } {
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          } if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k])); i+k<N i+k i k N dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k])) dp[i+k] dp i+k i k Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k])) Math.min Math dp[i+k] dp i+k i k dp[i] + Math.abs(arr[i] - arr[i+k]) dp[i] dp i Math.abs(arr[i] - arr[i+k]) Math.abs Math arr[i] - arr[i+k] arr[i] arr i arr[i+k] arr i+k i k output.println(dp[N-1]) output.println output dp[N-1] dp N-1 N 1 output.close() output.close output String[] args args public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
      	int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        }
        output.println(dp[N-1]);
      	output.close();
    }
} public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
      	int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        }
        output.println(dp[N-1]);
      	output.close();
    }
} Main
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(input.readLine());
        int N = Integer.parseInt(st.nextToken());
      	int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
          for(int k = 1; k<K+1; k++){
            if(i+k<N) dp[i+k] = Math.min(dp[i+k], dp[i] + Math.abs(arr[i] - arr[i+k]));
          }
        }
        output.println(dp[N-1]);
      	output.close();
    }
}