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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        
        int N = Integer.parseInt(nk[0]);
        int K = Integer.parseInt(nk[1]);
        
        String[] input = br.readLine().split(" ");
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        }
        
        System.out.println(getMinCost(h, K));
    }

    private static int getMinCost(int[] h, int k) {
        int[] cost = new int[h.length];
        
        for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }

        return cost[h.length-1];
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        
        int N = Integer.parseInt(nk[0]);
        int K = Integer.parseInt(nk[1]);
        
        String[] input = br.readLine().split(" ");
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        }
        
        System.out.println(getMinCost(h, K));
    }

    private static int getMinCost(int[] h, int k) {
        int[] cost = new int[h.length];
        
        for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }

        return cost[h.length-1];
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        
        int N = Integer.parseInt(nk[0]);
        int K = Integer.parseInt(nk[1]);
        
        String[] input = br.readLine().split(" ");
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        }
        
        System.out.println(getMinCost(h, K));
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        
        int N = Integer.parseInt(nk[0]);
        int K = Integer.parseInt(nk[1]);
        
        String[] input = br.readLine().split(" ");
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        }
        
        System.out.println(getMinCost(h, K));
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] nk = br.readLine().split(" "); nk br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int N = Integer.parseInt(nk[0]); N Integer.parseInt(nk[0]) Integer.parseInt Integer nk[0] nk 0 int K = Integer.parseInt(nk[1]); K Integer.parseInt(nk[1]) Integer.parseInt Integer nk[1] nk 1 String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            h[i] = Integer.parseInt(input[i]);
        } {
            h[i] = Integer.parseInt(input[i]);
        } h[i] = Integer.parseInt(input[i]) h[i] h i Integer.parseInt(input[i]) Integer.parseInt Integer input[i] input i System.out.println(getMinCost(h, K)) System.out.println System.out System System.out getMinCost(h, K) getMinCost h K String[] args args private static int getMinCost(int[] h, int k) {
        int[] cost = new int[h.length];
        
        for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }

        return cost[h.length-1];
    } getMinCost {
        int[] cost = new int[h.length];
        
        for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }

        return cost[h.length-1];
    } int[] cost = new int[h.length]; cost new int[h.length] h.length h h.length for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        } int i = 1; int i = 1; i 1 i < h.length i h.length h h.length i++ i++ i {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        } {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        } cost[i] = Integer.MAX_VALUE cost[i] cost i Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            } int j = k; int j = k; j k j > 0 j 0 j-- j-- j {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            } {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            } if(i-j < 0) continue; i-j < 0 i-j i j 0 continue; cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j])) cost[i] cost i Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j])) Math.min Math cost[i] cost i cost[i-j] + Math.abs(h[i] - h[i-j]) cost[i-j] cost i-j i j Math.abs(h[i] - h[i-j]) Math.abs Math h[i] - h[i-j] h[i] h i h[i-j] h i-j i j return cost[h.length-1]; cost[h.length-1] cost h.length-1 h.length h h.length 1 int[] h h int k k public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        
        int N = Integer.parseInt(nk[0]);
        int K = Integer.parseInt(nk[1]);
        
        String[] input = br.readLine().split(" ");
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        }
        
        System.out.println(getMinCost(h, K));
    }

    private static int getMinCost(int[] h, int k) {
        int[] cost = new int[h.length];
        
        for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }

        return cost[h.length-1];
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        
        int N = Integer.parseInt(nk[0]);
        int K = Integer.parseInt(nk[1]);
        
        String[] input = br.readLine().split(" ");
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        }
        
        System.out.println(getMinCost(h, K));
    }

    private static int getMinCost(int[] h, int k) {
        int[] cost = new int[h.length];
        
        for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }

        return cost[h.length-1];
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        
        int N = Integer.parseInt(nk[0]);
        int K = Integer.parseInt(nk[1]);
        
        String[] input = br.readLine().split(" ");
        int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(input[i]);
        }
        
        System.out.println(getMinCost(h, K));
    }

    private static int getMinCost(int[] h, int k) {
        int[] cost = new int[h.length];
        
        for (int i = 1; i < h.length; i++) {
            cost[i] = Integer.MAX_VALUE;
            for(int j = k; j > 0; j--) {
                if(i-j < 0) continue;
                cost[i] = Math.min(cost[i], cost[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }

        return cost[h.length-1];
    }
}