import java.io.*;
import java.util.*;
 
 
public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n  = sc.nextInt();
      int[] s = new int[n];
      int k = sc.nextInt();
      for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      }
      
      int[] dp = new int[n];
      boolean[] t = new boolean[n];
      for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      }
      //for (int i = 0; i < n; i++) out.println(dp[i]);
      out.println(dp[n-1]);
      out.close();
   }
  static int abs(int a, int b){
    if (b>a ) return b-a;
    return a-b;
  }
   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }
   
   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];
 
      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }
 
      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }
 
      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }
 
    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }
 
      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
}




 import java.io.*; io.* java import java.util.*; util.* java public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n  = sc.nextInt();
      int[] s = new int[n];
      int k = sc.nextInt();
      for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      }
      
      int[] dp = new int[n];
      boolean[] t = new boolean[n];
      for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      }
      //for (int i = 0; i < n; i++) out.println(dp[i]);
      out.println(dp[n-1]);
      out.close();
   }
  static int abs(int a, int b){
    if (b>a ) return b-a;
    return a-b;
  }
   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }
   
   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];
 
      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }
 
      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }
 
      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }
 
    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }
 
      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
} Main static int mod = (int)(Math.pow(10, 9) + 7); mod (int)(Math.pow(10, 9) + 7) Math.pow(10, 9) Math.pow Math 10 9 7 //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out; out public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n  = sc.nextInt();
      int[] s = new int[n];
      int k = sc.nextInt();
      for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      }
      
      int[] dp = new int[n];
      boolean[] t = new boolean[n];
      for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      }
      //for (int i = 0; i < n; i++) out.println(dp[i]);
      out.println(dp[n-1]);
      out.close();
   } main {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n  = sc.nextInt();
      int[] s = new int[n];
      int k = sc.nextInt();
      for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      }
      
      int[] dp = new int[n];
      boolean[] t = new boolean[n];
      for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      }
      //for (int i = 0; i < n; i++) out.println(dp[i]);
      out.println(dp[n-1]);
      out.close();
   } MyScanner sc = new MyScanner(); sc new MyScanner() out = new PrintWriter(new BufferedOutputStream(System.out)) out new PrintWriter(new BufferedOutputStream(System.out)) int n  = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] s = new int[n]; s new int[n] n int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      } int i = 0; int i = 0; i 0 i< n i n i++ i++ i {
        s[i] = sc.nextInt();
      } {
        s[i] = sc.nextInt();
      } s[i] = sc.nextInt() s[i] s i sc.nextInt() sc.nextInt sc int[] dp = new int[n]; dp new int[n] n boolean[] t = new boolean[n]; t new boolean[n] n for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      } {
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      } for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        } int j = 1; int j = 1; j 1 j <= k j k j++ j++ j {
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        } {
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        } if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        } i < n-j i n-j n j {
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        } if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          } !t[i+j] t[i+j] t i+j i j {
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          } t[i+j] = true t[i+j] t i+j i j true dp[i+j] = dp[i] + abs(s[i], s[i+j]) dp[i+j] dp i+j i j dp[i] + abs(s[i], s[i+j]) dp[i] dp i abs(s[i], s[i+j]) abs s[i] s i s[i+j] s i+j i j {
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          } dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]) dp[i+j] dp i+j i j Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]) Integer.min Integer dp[i] + abs(s[i],s[i+j]) dp[i] dp i abs(s[i],s[i+j]) abs s[i] s i s[i+j] s i+j i j dp[i+j] dp i+j i j out.println(dp[n-1]) out.println out dp[n-1] dp n-1 n 1 out.close() out.close out String[] args args static int abs(int a, int b){
    if (b>a ) return b-a;
    return a-b;
  } abs {
    if (b>a ) return b-a;
    return a-b;
  } if (b>a ) return b-a; b>a b a return b-a; b-a b a return a-b; a-b a b int a a int b b static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   } pow {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   } if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   } N == 0 N 0 return 1; 1 if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   } N == 1 N 1 return a; a {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   } long R = pow(a,N/2); R pow(a,N/2) pow a N/2 N 2 if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   } N % 2 == 0 N % 2 N 2 0 {
			   return R*R;
		   } return R*R; R*R R R {
			   return R*R*a;
		   } return R*R*a; R*R*a R*R*a R R a long a a long N N static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   } powMod {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   } if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   } N == 0 N 0 return 1; 1 if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   } N == 1 N 1 return a % mod; a % mod a mod {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   } long R = powMod(a,N/2) % mod; R powMod(a,N/2) % mod powMod(a,N/2) powMod a N/2 N 2 mod R *= R % mod R R % mod R mod if (N % 2 == 0) {
			   R *= a % mod;
		   } N % 2 == 0 N % 2 N 2 0 {
			   R *= a % mod;
		   } R *= a % mod R a % mod a mod return R % mod; R % mod R mod long a a long N N static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];
 
      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }
 
      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }
 
      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    } mergeSort { // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];
 
      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }
 
      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }
 
      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    } int n = A.length; n A.length A A.length if (n < 2) return; n < 2 n 2 return; int[] l = new int[n/2]; l new int[n/2] n/2 n 2 int[] r = new int[n - n/2]; r new int[n - n/2] n - n/2 n n/2 n 2 for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      } int i = 0; int i = 0; i 0 i < n/2 i n/2 n 2 i++ i++ i {
        l[i] = A[i];
      } {
        l[i] = A[i];
      } l[i] = A[i] l[i] l i A[i] A i for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      } int j = n/2; int j = n/2; j n/2 n 2 j < n j n j++ j++ j {
        r[j-n/2] = A[j];
      } {
        r[j-n/2] = A[j];
      } r[j-n/2] = A[j] r[j-n/2] r j-n/2 j n/2 n 2 A[j] A j mergeSort(l) mergeSort l mergeSort(r) mergeSort r merge(l, r, A) merge l r A int[] A A static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }
 
      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    } merge {
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }
 
      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    } int i = 0 i 0 j = 0 j 0 k = 0; k 0 while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      } i < l.length && j < r.length && k < a.length i < l.length && j < r.length && k < a.length i < l.length i l.length l l.length j < r.length j r.length r r.length k < a.length k a.length a a.length {
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      } if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        } l[i] < r[j] l[i] l i r[j] r j {
          a[k] = l[i];
          i++;
        } a[k] = l[i] a[k] a k l[i] l i i++ i {
          a[k] = r[j];
          j++;
        } a[k] = r[j] a[k] a k r[j] r j j++ j k++ k while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      } i < l.length i l.length l l.length {
        a[k] = l[i];
        i++;
        k++;
      } a[k] = l[i] a[k] a k l[i] l i i++ i k++ k while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      } j < r.length j r.length r r.length {
        a[k] = r[j];
        j++;
        k++;
      } a[k] = r[j] a[k] a k r[j] r j j++ j k++ k int[] l l int[] r r int[] a a public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   } MyScanner BufferedReader br; br StringTokenizer st; st public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      } MyScanner {
         br = new BufferedReader(new InputStreamReader(System.in));
      } br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      } next {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      } while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          } try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              } IOException e {
                  e.printStackTrace();
              } e.printStackTrace() e.printStackTrace e {
                  st = new StringTokenizer(br.readLine());
              } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {
          return Integer.parseInt(next());
      } nextInt {
          return Integer.parseInt(next());
      } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() {
          return Long.parseLong(next());
      } nextLong {
          return Long.parseLong(next());
      } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next double nextDouble() {
          return Double.parseDouble(next());
      } nextDouble {
          return Double.parseDouble(next());
      } return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      } nextLine {
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      } String str = ""; str "" try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  } catch (IOException e) {
	     e.printStackTrace();
	  } IOException e {
	     e.printStackTrace();
	  } e.printStackTrace() e.printStackTrace e {
	     str = br.readLine();
	  } str = br.readLine() str br.readLine() br.readLine br return str; str public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n  = sc.nextInt();
      int[] s = new int[n];
      int k = sc.nextInt();
      for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      }
      
      int[] dp = new int[n];
      boolean[] t = new boolean[n];
      for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      }
      //for (int i = 0; i < n; i++) out.println(dp[i]);
      out.println(dp[n-1]);
      out.close();
   }
  static int abs(int a, int b){
    if (b>a ) return b-a;
    return a-b;
  }
   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }
   
   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];
 
      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }
 
      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }
 
      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }
 
    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }
 
      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
} public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n  = sc.nextInt();
      int[] s = new int[n];
      int k = sc.nextInt();
      for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      }
      
      int[] dp = new int[n];
      boolean[] t = new boolean[n];
      for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      }
      //for (int i = 0; i < n; i++) out.println(dp[i]);
      out.println(dp[n-1]);
      out.close();
   }
  static int abs(int a, int b){
    if (b>a ) return b-a;
    return a-b;
  }
   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }
   
   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];
 
      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }
 
      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }
 
      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }
 
    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }
 
      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
} Main
import java.io.*;
import java.util.*;
 
 
public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n  = sc.nextInt();
      int[] s = new int[n];
      int k = sc.nextInt();
      for (int i = 0; i< n; i++){
        s[i] = sc.nextInt();
      }
      
      int[] dp = new int[n];
      boolean[] t = new boolean[n];
      for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++){
          if (i < n-j){
          if (!t[i+j]){
            t[i+j] = true;
            dp[i+j] = dp[i] + abs(s[i], s[i+j]);
          }
          else{
            dp[i+j] = Integer.min(dp[i] + abs(s[i],s[i+j]), dp[i+j]); 
          }
        }
        }
        
        
      }
      //for (int i = 0; i < n; i++) out.println(dp[i]);
      out.println(dp[n-1]);
      out.close();
   }
  static int abs(int a, int b){
    if (b>a ) return b-a;
    return a-b;
  }
   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }
   
   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 0) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];
 
      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }
 
      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }
 
      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }
 
    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }
 
      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
}





