import java.util.*;
public class Main {
    public static void main(String argd[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int asi[] = new int[N];
        int dp[] = new int[N];
        for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        }
        dp[0] = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        }
        System.out.println(dp[N - 1]);
        
    }
    
} import java.util.*; util.* java public class Main {
    public static void main(String argd[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int asi[] = new int[N];
        int dp[] = new int[N];
        for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        }
        dp[0] = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        }
        System.out.println(dp[N - 1]);
        
    }
    
} Main public static void main(String argd[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int asi[] = new int[N];
        int dp[] = new int[N];
        for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        }
        dp[0] = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        }
        System.out.println(dp[N - 1]);
        
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int asi[] = new int[N];
        int dp[] = new int[N];
        for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        }
        dp[0] = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        }
        System.out.println(dp[N - 1]);
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int asi[] = new int[N]; asi new int[N] N int dp[] = new int[N]; dp new int[N] N for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        } {
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        } asi[i] = sc.nextInt() asi[i] asi i sc.nextInt() sc.nextInt sc dp[i] = 2000000000 dp[i] dp i 2000000000 dp[0] = 0 dp[0] dp 0 0 for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        } {
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        } for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j <= K + i && j < dp.length j <= K + i j K + i K i j < dp.length j dp.length dp dp.length j++ j++ j {
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            } {
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            } if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i]; dp[j] > dp[i] + Math.abs(asi[i] - asi[j]) dp[j] dp j dp[i] + Math.abs(asi[i] - asi[j]) dp[i] dp i Math.abs(asi[i] - asi[j]) Math.abs Math asi[i] - asi[j] asi[i] asi i asi[j] asi j dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i] dp[j] dp j Math.abs(asi[i] - asi[j]) + dp[i] Math.abs(asi[i] - asi[j]) Math.abs Math asi[i] - asi[j] asi[i] asi i asi[j] asi j dp[i] dp i System.out.println(dp[N - 1]) System.out.println System.out System System.out dp[N - 1] dp N - 1 N 1 String argd[] argd public class Main {
    public static void main(String argd[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int asi[] = new int[N];
        int dp[] = new int[N];
        for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        }
        dp[0] = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        }
        System.out.println(dp[N - 1]);
        
    }
    
} public class Main {
    public static void main(String argd[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int asi[] = new int[N];
        int dp[] = new int[N];
        for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        }
        dp[0] = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        }
        System.out.println(dp[N - 1]);
        
    }
    
} Main
import java.util.*;
public class Main {
    public static void main(String argd[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int asi[] = new int[N];
        int dp[] = new int[N];
        for(int i = 0; i < N; i++){
            asi[i] = sc.nextInt();
            dp[i] = 2000000000;
        }
        dp[0] = 0;
        for(int i = 0; i < N - 1; i++){
            for(int j = i + 1; j <= K + i && j < dp.length; j++){
                if(dp[j] > dp[i] + Math.abs(asi[i] - asi[j])) dp[j] =  Math.abs(asi[i] - asi[j]) + dp[i];
            }
        }
        System.out.println(dp[N - 1]);
        
    }
    
}