import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Arrays; Arrays java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    } main {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    } BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in)); br new BufferedReader(new java.io.InputStreamReader(System.in)) PrintWriter pw = new PrintWriter(System.out); pw new PrintWriter(System.out) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.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 String[] input_str_array = br.readLine().split(" "); input_str_array br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] input_array = new int[N]; input_array new int[N] N for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        } {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        } input_array[i] = Integer.parseInt(input_str_array[i]) input_array[i] input_array i Integer.parseInt(input_str_array[i]) Integer.parseInt Integer input_str_array[i] input_str_array i int[] dp = new int[N]; dp new int[N] N Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 dp[0] = 0 dp[0] dp 0 0 for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        } {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        } for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            } int j = 1; int j = 1; j 1 j <= K j K j++ j++ j {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            } {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            } if(i+j > N-1) break; i+j > N-1 i+j i j N-1 N 1 break; if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                } dp[i + j] == -1 dp[i + j] dp i + j i j -1 1 {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i] dp[i + j] dp i + j i j Math.abs(input_array[i] - input_array[i + j]) + dp[i] Math.abs(input_array[i] - input_array[i + j]) Math.abs Math input_array[i] - input_array[i + j] input_array[i] input_array i input_array[i + j] input_array i + j i j dp[i] dp i {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                } dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]) dp[i + j] dp i + j i j Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]) Math.min Math Math.abs(input_array[i] - input_array[i + j]) + dp[i] Math.abs(input_array[i] - input_array[i + j]) Math.abs Math input_array[i] - input_array[i + j] input_array[i] input_array i input_array[i + j] input_array i + j i j dp[i] dp i dp[i + j] dp i + j i j pw.println(dp[N-1]) pw.println pw dp[N-1] dp N-1 N 1 pw.close() pw.close pw br.close() br.close br String[] args args public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    }
}
