import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author radhakm
 */
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
}



public class Main {
    static int[] h;
    static int n;
    static int k;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        k = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }
        int minCost = Integer.MAX_VALUE;
        for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        }
        dp[idx] = minCost;
        return minCost;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
} InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    } InputReader {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    } reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    } next {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } IOException e {
                throw new RuntimeException(e);
            } throw new RuntimeException(e); new RuntimeException(e) {
                tokenizer = new StringTokenizer(reader.readLine());
            } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public int nextInt() {
        return Integer.parseInt(next());
    } nextInt {
        return Integer.parseInt(next());
    } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
    static int[] h;
    static int n;
    static int k;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        k = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }
        int minCost = Integer.MAX_VALUE;
        for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        }
        dp[idx] = minCost;
        return minCost;
    }
} Main static int[] h; h static int n; n static int k; k static Integer[] dp; dp public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        k = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    } main {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        k = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    } InputReader reader = new InputReader(System.in); reader new InputReader(System.in) n = reader.nextInt() n reader.nextInt() reader.nextInt reader k = reader.nextInt() k reader.nextInt() reader.nextInt reader h = new int[n] h new int[n] n dp = new Integer[n] dp new Integer[n] n for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            h[i] = reader.nextInt();
        } {
            h[i] = reader.nextInt();
        } h[i] = reader.nextInt() h[i] h i reader.nextInt() reader.nextInt reader System.out.println(frogJump(0)) System.out.println System.out System System.out frogJump(0) frogJump 0 String[] args args static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }
        int minCost = Integer.MAX_VALUE;
        for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        }
        dp[idx] = minCost;
        return minCost;
    } frogJump {
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }
        int minCost = Integer.MAX_VALUE;
        for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        }
        dp[idx] = minCost;
        return minCost;
    } if(idx == n-1){
            return 0;
        } idx == n-1 idx n-1 n 1 {
            return 0;
        } return 0; 0 if(dp[idx]!=null){
            return dp[idx];
        } dp[idx]!=null dp[idx] dp idx null {
            return dp[idx];
        } return dp[idx]; dp[idx] dp idx int minCost = Integer.MAX_VALUE; minCost Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        } {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        } if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            } idx + i < n idx + i idx i n {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            } int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i); cost Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i) Math.abs(h[idx] - h[idx + i]) Math.abs Math h[idx] - h[idx + i] h[idx] h idx h[idx + i] h idx + i idx i frogJump(idx + i) frogJump idx + i idx i minCost = Math.min(minCost, cost) minCost Math.min(minCost, cost) Math.min Math minCost cost dp[idx] = minCost dp[idx] dp idx minCost return minCost; minCost int idx idx public class Main {
    static int[] h;
    static int n;
    static int k;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        k = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }
        int minCost = Integer.MAX_VALUE;
        for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        }
        dp[idx] = minCost;
        return minCost;
    }
} public class Main {
    static int[] h;
    static int n;
    static int k;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        k = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }
        int minCost = Integer.MAX_VALUE;
        for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        }
        dp[idx] = minCost;
        return minCost;
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author radhakm
 */
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
}



public class Main {
    static int[] h;
    static int n;
    static int k;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        k = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }
        int minCost = Integer.MAX_VALUE;
        for(int i=1;i<=k;i++) {
            if (idx + i < n) {
                int cost = Math.abs(h[idx] - h[idx + i]) + frogJump(idx + i);
                minCost = Math.min(minCost, cost);
            }
        }
        dp[idx] = minCost;
        return minCost;
    }
}