import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int  k = s.nextInt();
    int arr[] = new int[n];
    for(int i = 0 ; i<n ; i++ ) {
      arr[i] = s.nextInt();
    }
    int dp[] = new int[n];
    dp[0] = 0;
    dp[1] = Math.abs(arr[1]-arr[0]);
    for (int i =2 ; i< n ;i++) {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    }
      
 	System.out.println(dp[dp.length-1]);
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int  k = s.nextInt();
    int arr[] = new int[n];
    for(int i = 0 ; i<n ; i++ ) {
      arr[i] = s.nextInt();
    }
    int dp[] = new int[n];
    dp[0] = 0;
    dp[1] = Math.abs(arr[1]-arr[0]);
    for (int i =2 ; i< n ;i++) {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    }
      
 	System.out.println(dp[dp.length-1]);
  }
} Main public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int  k = s.nextInt();
    int arr[] = new int[n];
    for(int i = 0 ; i<n ; i++ ) {
      arr[i] = s.nextInt();
    }
    int dp[] = new int[n];
    dp[0] = 0;
    dp[1] = Math.abs(arr[1]-arr[0]);
    for (int i =2 ; i< n ;i++) {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    }
      
 	System.out.println(dp[dp.length-1]);
  } main {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int  k = s.nextInt();
    int arr[] = new int[n];
    for(int i = 0 ; i<n ; i++ ) {
      arr[i] = s.nextInt();
    }
    int dp[] = new int[n];
    dp[0] = 0;
    dp[1] = Math.abs(arr[1]-arr[0]);
    for (int i =2 ; i< n ;i++) {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    }
      
 	System.out.println(dp[dp.length-1]);
  } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int  k = s.nextInt(); k s.nextInt() s.nextInt s int arr[] = new int[n]; arr new int[n] n for(int i = 0 ; i<n ; i++ ) {
      arr[i] = s.nextInt();
    } int i = 0 ; int i = 0 ; i 0 i<n i n i++ i++ i {
      arr[i] = s.nextInt();
    } {
      arr[i] = s.nextInt();
    } arr[i] = s.nextInt() arr[i] arr i s.nextInt() s.nextInt s int dp[] = new int[n]; dp new int[n] n dp[0] = 0 dp[0] dp 0 0 dp[1] = Math.abs(arr[1]-arr[0]) dp[1] dp 1 Math.abs(arr[1]-arr[0]) Math.abs Math arr[1]-arr[0] arr[1] arr 1 arr[0] arr 0 for (int i =2 ; i< n ;i++) {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    } int i =2 ; int i =2 ; i 2 i< n i n i++ i++ i {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    } {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    } int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        } int j = 1 ; int j = 1 ; j 1 j<=k j k j++ j++ j {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        } {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        } if(i-j<0) {
                break;
            } i-j<0 i-j i j 0 {
                break;
            } break; int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j]; lo Math.abs(-arr[i-j]+arr[i])+dp[i-j] Math.abs(-arr[i-j]+arr[i]) Math.abs Math -arr[i-j]+arr[i] -arr[i-j] arr[i-j] arr i-j i j arr[i] arr i dp[i-j] dp i-j i j if(min>lo) {
                min = lo;
            } min>lo min lo {
                min = lo;
            } min = lo min lo dp[i] = min dp[i] dp i min System.out.println(dp[dp.length-1]) System.out.println System.out System System.out dp[dp.length-1] dp dp.length-1 dp.length dp dp.length 1 String[] args args
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int  k = s.nextInt();
    int arr[] = new int[n];
    for(int i = 0 ; i<n ; i++ ) {
      arr[i] = s.nextInt();
    }
    int dp[] = new int[n];
    dp[0] = 0;
    dp[1] = Math.abs(arr[1]-arr[0]);
    for (int i =2 ; i< n ;i++) {
        int min = Integer.MAX_VALUE;
        for (int j = 1 ; j<=k ;j++) {
            if(i-j<0) {
                break;
            }
            int lo = Math.abs(-arr[i-j]+arr[i])+dp[i-j];
            if(min>lo) {
                min = lo;
            }
        }
        dp[i] = min;
        //System.out.print(dp[i]+" ");
    }
      
 	System.out.println(dp[dp.length-1]);
  }
}