import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
} Main public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } IOException e {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } e.printStackTrace() e.printStackTrace e {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } String[] tmp = br.readLine().split(" "); tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int N = Integer.valueOf(tmp[0]) N Integer.valueOf(tmp[0]) Integer.valueOf Integer tmp[0] tmp 0 K = Integer.valueOf(tmp[1]); K Integer.valueOf(tmp[1]) Integer.valueOf Integer tmp[1] tmp 1 tmp = br.readLine().split(" ") tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] arr = new int[N]; arr new int[N] N for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                arr[i] = Integer.valueOf(tmp[i]);
            } {
                arr[i] = Integer.valueOf(tmp[i]);
            } arr[i] = Integer.valueOf(tmp[i]) arr[i] arr i Integer.valueOf(tmp[i]) Integer.valueOf Integer tmp[i] tmp i 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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                for (int j = i + 1; j < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            } {
                for (int j = i + 1; j < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            } for (int j = i + 1; j < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                } int j = i + 1; int j = i + 1; j i + 1 i 1 j < Math.min(N, i + K + 1) j Math.min(N, i + K + 1) Math.min Math N i + K + 1 i + K + 1 i K 1 j++ j++ j {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                } {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                } dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i])) dp[j] dp j Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i])) Math.min Math dp[j] dp j dp[i] + Math.abs(arr[j] - arr[i]) dp[i] dp i Math.abs(arr[j] - arr[i]) Math.abs Math arr[j] - arr[i] arr[j] arr j arr[i] arr i 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) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
} public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] tmp = br.readLine().split(" ");
            int N = Integer.valueOf(tmp[0]), K = Integer.valueOf(tmp[1]);

            tmp = br.readLine().split(" ");
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = Integer.valueOf(tmp[i]);
            }

            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 < Math.min(N, i + K + 1); j++) {
                    dp[j] = Math.min(dp[j], dp[i] + Math.abs(arr[j] - arr[i]));
                }
            }

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

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
}