/////////////package Educ_DP;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] l=s.nextLine().split(" ");
        int num=Integer.parseInt(l[0]);
        int max=Integer.parseInt(l[1]);

        int[] list=new int[num];
        String[] t=s.nextLine().split(" ");
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        }
        int[] dp=new int[num];
        Arrays.fill(dp,-1);
        dp[dp.length-1]=0;
        dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]);

        for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        }
       
        System.out.println(dp[0]);
    }
} import javax.swing.plaf.basic.BasicInternalFrameTitlePane; BasicInternalFrameTitlePane javax.swing.plaf.basic import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] l=s.nextLine().split(" ");
        int num=Integer.parseInt(l[0]);
        int max=Integer.parseInt(l[1]);

        int[] list=new int[num];
        String[] t=s.nextLine().split(" ");
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        }
        int[] dp=new int[num];
        Arrays.fill(dp,-1);
        dp[dp.length-1]=0;
        dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]);

        for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        }
       
        System.out.println(dp[0]);
    }
} Main public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] l=s.nextLine().split(" ");
        int num=Integer.parseInt(l[0]);
        int max=Integer.parseInt(l[1]);

        int[] list=new int[num];
        String[] t=s.nextLine().split(" ");
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        }
        int[] dp=new int[num];
        Arrays.fill(dp,-1);
        dp[dp.length-1]=0;
        dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]);

        for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        }
       
        System.out.println(dp[0]);
    } main {
        Scanner s = new Scanner(System.in);
        String[] l=s.nextLine().split(" ");
        int num=Integer.parseInt(l[0]);
        int max=Integer.parseInt(l[1]);

        int[] list=new int[num];
        String[] t=s.nextLine().split(" ");
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        }
        int[] dp=new int[num];
        Arrays.fill(dp,-1);
        dp[dp.length-1]=0;
        dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]);

        for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        }
       
        System.out.println(dp[0]);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) String[] l=s.nextLine().split(" "); l s.nextLine().split(" ") s.nextLine().split s.nextLine() s.nextLine s " " int num=Integer.parseInt(l[0]); num Integer.parseInt(l[0]) Integer.parseInt Integer l[0] l 0 int max=Integer.parseInt(l[1]); max Integer.parseInt(l[1]) Integer.parseInt Integer l[1] l 1 int[] list=new int[num]; list new int[num] num String[] t=s.nextLine().split(" "); t s.nextLine().split(" ") s.nextLine().split s.nextLine() s.nextLine s " " for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        } int i=0; int i=0; i 0 i<list.length i list.length list list.length i++ i++ i {
            list[i]=Integer.parseInt(t[i]);
        } {
            list[i]=Integer.parseInt(t[i]);
        } list[i]=Integer.parseInt(t[i]) list[i] list i Integer.parseInt(t[i]) Integer.parseInt Integer t[i] t i int[] dp=new int[num]; dp new int[num] num Arrays.fill(dp,-1) Arrays.fill Arrays dp -1 1 dp[dp.length-1]=0 dp[dp.length-1] dp dp.length-1 dp.length dp dp.length 1 0 dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]) dp[dp.length-2] dp dp.length-2 dp.length dp dp.length 2 dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]) dp[dp.length-1] dp dp.length-1 dp.length dp dp.length 1 Math.abs(list[list.length-1]-list[list.length-2]) Math.abs Math list[list.length-1]-list[list.length-2] list[list.length-1] list list.length-1 list.length list list.length 1 list[list.length-2] list list.length-2 list.length list list.length 2 for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        } int i=dp.length-3; int i=dp.length-3; i dp.length-3 dp.length dp dp.length 3 i>=0 i 0 i-- i-- i {
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        } {
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        } for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            } int j=max+i; int j=max+i; j max+i max i j>i j i j-- j-- j {
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            } {
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            } if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                } j<list.length j list.length list list.length {
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                } int x=dp[j]+ Math.abs(list[i]-list[j]); x dp[j]+ Math.abs(list[i]-list[j]) dp[j] dp j Math.abs(list[i]-list[j]) Math.abs Math list[i]-list[j] list[i] list i list[j] list j if (dp[i]==-1){
                        dp[i]=x;
                    } dp[i]==-1 dp[i] dp i -1 1 {
                        dp[i]=x;
                    } dp[i]=x dp[i] dp i x dp[i]=Math.min(dp[i],x) dp[i] dp i Math.min(dp[i],x) Math.min Math dp[i] dp i x System.out.println(dp[0]) System.out.println System.out System System.out dp[0] dp 0 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] l=s.nextLine().split(" ");
        int num=Integer.parseInt(l[0]);
        int max=Integer.parseInt(l[1]);

        int[] list=new int[num];
        String[] t=s.nextLine().split(" ");
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        }
        int[] dp=new int[num];
        Arrays.fill(dp,-1);
        dp[dp.length-1]=0;
        dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]);

        for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        }
       
        System.out.println(dp[0]);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] l=s.nextLine().split(" ");
        int num=Integer.parseInt(l[0]);
        int max=Integer.parseInt(l[1]);

        int[] list=new int[num];
        String[] t=s.nextLine().split(" ");
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        }
        int[] dp=new int[num];
        Arrays.fill(dp,-1);
        dp[dp.length-1]=0;
        dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]);

        for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        }
       
        System.out.println(dp[0]);
    }
} Main
/////////////package Educ_DP;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] l=s.nextLine().split(" ");
        int num=Integer.parseInt(l[0]);
        int max=Integer.parseInt(l[1]);

        int[] list=new int[num];
        String[] t=s.nextLine().split(" ");
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(t[i]);
        }
        int[] dp=new int[num];
        Arrays.fill(dp,-1);
        dp[dp.length-1]=0;
        dp[dp.length-2]=dp[dp.length-1]+Math.abs(list[list.length-1]-list[list.length-2]);

        for (int i=dp.length-3;i>=0;i--){
            for (int j=max+i;j>i;j--){
                if (j<list.length){
                    int x=dp[j]+ Math.abs(list[i]-list[j]);
                    if (dp[i]==-1){
                        dp[i]=x;
                    }
                    dp[i]=Math.min(dp[i],x);
                }
            }
        }
       
        System.out.println(dp[0]);
    }
}
