
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long INF = 1L << 60;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[110000];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[110000];
        Arrays.fill(dp,INF);
        dp[0] = 0;

        for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        }
        System.out.println(dp[N-1]);
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long INF = 1L << 60;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[110000];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[110000];
        Arrays.fill(dp,INF);
        dp[0] = 0;

        for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        }
        System.out.println(dp[N-1]);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long INF = 1L << 60;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[110000];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[110000];
        Arrays.fill(dp,INF);
        dp[0] = 0;

        for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        }
        System.out.println(dp[N-1]);
    } main {
        Scanner sc = new Scanner(System.in);
        long INF = 1L << 60;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[110000];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[110000];
        Arrays.fill(dp,INF);
        dp[0] = 0;

        for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        }
        System.out.println(dp[N-1]);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long INF = 1L << 60; INF 1L << 60 1L 60 int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int[] arr = new int[110000]; arr new int[110000] 110000 for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            arr[i] = sc.nextInt();
        } {
            arr[i] = sc.nextInt();
        } arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc long[] dp = new long[110000]; dp new long[110000] 110000 Arrays.fill(dp,INF) Arrays.fill Arrays dp INF dp[0] = 0 dp[0] dp 0 0 for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        } int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        } {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        } for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            } int k = 1; int k = 1; k 1 k <= K k K k++ k++ k {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            } {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            } dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k])) dp[j+k] dp j+k j k Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k])) Math.min Math dp[j+k] dp j+k j k dp[j] + Math.abs(arr[j] - arr[j+k]) dp[j] dp j Math.abs(arr[j] - arr[j+k]) Math.abs Math arr[j] - arr[j+k] arr[j] arr j arr[j+k] arr j+k j k 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) {
        Scanner sc = new Scanner(System.in);
        long INF = 1L << 60;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[110000];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[110000];
        Arrays.fill(dp,INF);
        dp[0] = 0;

        for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        }
        System.out.println(dp[N-1]);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long INF = 1L << 60;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[110000];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[110000];
        Arrays.fill(dp,INF);
        dp[0] = 0;

        for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        }
        System.out.println(dp[N-1]);
    }
} Main

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long INF = 1L << 60;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[110000];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[110000];
        Arrays.fill(dp,INF);
        dp[0] = 0;

        for(int j = 0; j < N; j++) {
            for(int k = 1; k <= K; k++) {
                dp[j+k] = Math.min(dp[j+k],dp[j] + Math.abs(arr[j] - arr[j+k]));
            }
        }
        System.out.println(dp[N-1]);
    }
}
