import java.util.*;
import java.io.*;
public class Main {
    public static void main(String args[]) {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int k=input.nextInt();
        int cost[]=new int[n];
        for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        }
        System.out.println(solve(n,k,cost));
    }
    public static int solve(int n,int k,int[] cost) {
        int dp[]=new int[n];
        dp[1]=Math.abs(cost[0]-cost[1]);
        for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        }
        return dp[n-1];
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String args[]) {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int k=input.nextInt();
        int cost[]=new int[n];
        for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        }
        System.out.println(solve(n,k,cost));
    }
    public static int solve(int n,int k,int[] cost) {
        int dp[]=new int[n];
        dp[1]=Math.abs(cost[0]-cost[1]);
        for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        }
        return dp[n-1];
    }
} Main public static void main(String args[]) {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int k=input.nextInt();
        int cost[]=new int[n];
        for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        }
        System.out.println(solve(n,k,cost));
    } main {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int k=input.nextInt();
        int cost[]=new int[n];
        for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        }
        System.out.println(solve(n,k,cost));
    } Scanner input=new Scanner(System.in); input new Scanner(System.in) int n=input.nextInt(); n input.nextInt() input.nextInt input int k=input.nextInt(); k input.nextInt() input.nextInt input int cost[]=new int[n]; cost new int[n] n for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            cost[i]=input.nextInt();
        } {
            cost[i]=input.nextInt();
        } cost[i]=input.nextInt() cost[i] cost i input.nextInt() input.nextInt input System.out.println(solve(n,k,cost)) System.out.println System.out System System.out solve(n,k,cost) solve n k cost String args[] args public static int solve(int n,int k,int[] cost) {
        int dp[]=new int[n];
        dp[1]=Math.abs(cost[0]-cost[1]);
        for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        }
        return dp[n-1];
    } solve {
        int dp[]=new int[n];
        dp[1]=Math.abs(cost[0]-cost[1]);
        for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        }
        return dp[n-1];
    } int dp[]=new int[n]; dp new int[n] n dp[1]=Math.abs(cost[0]-cost[1]) dp[1] dp 1 Math.abs(cost[0]-cost[1]) Math.abs Math cost[0]-cost[1] cost[0] cost 0 cost[1] cost 1 for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        } int i=2; int i=2; i 2 i<n i n i++ i++ i {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        } {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        } dp[i]=Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            } int j=1; int j=1; j 1 j<=Math.min(i,k) j Math.min(i,k) Math.min Math i k j++ j++ j {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            } {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            } dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j])) dp[i] dp i Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j])) Math.min Math dp[i] dp i dp[i-j]+Math.abs(cost[i]-cost[i-j]) dp[i-j] dp i-j i j Math.abs(cost[i]-cost[i-j]) Math.abs Math cost[i]-cost[i-j] cost[i] cost i cost[i-j] cost i-j i j return dp[n-1]; dp[n-1] dp n-1 n 1 int n n int k k int[] cost cost public class Main {
    public static void main(String args[]) {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int k=input.nextInt();
        int cost[]=new int[n];
        for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        }
        System.out.println(solve(n,k,cost));
    }
    public static int solve(int n,int k,int[] cost) {
        int dp[]=new int[n];
        dp[1]=Math.abs(cost[0]-cost[1]);
        for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        }
        return dp[n-1];
    }
} public class Main {
    public static void main(String args[]) {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int k=input.nextInt();
        int cost[]=new int[n];
        for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        }
        System.out.println(solve(n,k,cost));
    }
    public static int solve(int n,int k,int[] cost) {
        int dp[]=new int[n];
        dp[1]=Math.abs(cost[0]-cost[1]);
        for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        }
        return dp[n-1];
    }
} Main
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String args[]) {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int k=input.nextInt();
        int cost[]=new int[n];
        for(int i=0;i<n;i++) {
            cost[i]=input.nextInt();
        }
        System.out.println(solve(n,k,cost));
    }
    public static int solve(int n,int k,int[] cost) {
        int dp[]=new int[n];
        dp[1]=Math.abs(cost[0]-cost[1]);
        for(int i=2;i<n;i++) {
            dp[i]=Integer.MAX_VALUE;
            for(int j=1;j<=Math.min(i,k);j++) {
                dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(cost[i]-cost[i-j]));
            }
        }
        return dp[n-1];
    }
}
