import java.util.*;

public class Main{
  public static long dp[]=new long[100001];
  public static long go(long a[],int i,int k){
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 1000000000;
    }
    if(dp[i]!=-1)
    return dp[i];
    long min=1000000000;
    for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    }
    return dp[i];
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int k=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    }
    dp[n]=-1;
    System.out.print(go(a,0,k));
  }
} import java.util.*; util.* java public class Main{
  public static long dp[]=new long[100001];
  public static long go(long a[],int i,int k){
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 1000000000;
    }
    if(dp[i]!=-1)
    return dp[i];
    long min=1000000000;
    for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    }
    return dp[i];
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int k=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    }
    dp[n]=-1;
    System.out.print(go(a,0,k));
  }
} Main public static long dp[]=new long[100001]; dp new long[100001] 100001 public static long go(long a[],int i,int k){
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 1000000000;
    }
    if(dp[i]!=-1)
    return dp[i];
    long min=1000000000;
    for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    }
    return dp[i];
  } go {
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 1000000000;
    }
    if(dp[i]!=-1)
    return dp[i];
    long min=1000000000;
    for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    }
    return dp[i];
  } if(i==a.length-1)
    {
      return 0;
    } i==a.length-1 i a.length-1 a.length a a.length 1 {
      return 0;
    } return 0; 0 if(i>a.length-1)
    {
      return 1000000000;
    } i>a.length-1 i a.length-1 a.length a a.length 1 {
      return 1000000000;
    } return 1000000000; 1000000000 if(dp[i]!=-1)
    return dp[i]; dp[i]!=-1 dp[i] dp i -1 1 return dp[i]; dp[i] dp i long min=1000000000; min 1000000000 for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    } int j=i+1; int j=i+1; j i+1 i 1 j<=i+k j i+k i k j++ j++ j {
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    } {
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    } long cost; cost if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      } j<=a.length-1 j a.length-1 a.length a a.length 1 {
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      } cost=Math.abs(a[i]-a[j])+go(a,j,k) cost Math.abs(a[i]-a[j])+go(a,j,k) Math.abs(a[i]-a[j]) Math.abs Math a[i]-a[j] a[i] a i a[j] a j go(a,j,k) go a j k min=Math.min(cost,min) min Math.min(cost,min) Math.min Math cost min dp[i]=min dp[i] dp i min return dp[i]; dp[i] dp i long a[] a int i i int k k public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int k=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    }
    dp[n]=-1;
    System.out.print(go(a,0,k));
  } main {
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int k=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    }
    dp[n]=-1;
    System.out.print(go(a,0,k));
  } 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 long a[]=new long[n]; a new long[n] n for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
    dp[i]=-1;
    a[i]=sc.nextLong();
    } {
    dp[i]=-1;
    a[i]=sc.nextLong();
    } dp[i]=-1 dp[i] dp i -1 1 a[i]=sc.nextLong() a[i] a i sc.nextLong() sc.nextLong sc dp[n]=-1 dp[n] dp n -1 1 System.out.print(go(a,0,k)) System.out.print System.out System System.out go(a,0,k) go a 0 k String[] args args public class Main{
  public static long dp[]=new long[100001];
  public static long go(long a[],int i,int k){
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 1000000000;
    }
    if(dp[i]!=-1)
    return dp[i];
    long min=1000000000;
    for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    }
    return dp[i];
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int k=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    }
    dp[n]=-1;
    System.out.print(go(a,0,k));
  }
} public class Main{
  public static long dp[]=new long[100001];
  public static long go(long a[],int i,int k){
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 1000000000;
    }
    if(dp[i]!=-1)
    return dp[i];
    long min=1000000000;
    for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    }
    return dp[i];
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int k=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    }
    dp[n]=-1;
    System.out.print(go(a,0,k));
  }
} Main
import java.util.*;

public class Main{
  public static long dp[]=new long[100001];
  public static long go(long a[],int i,int k){
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 1000000000;
    }
    if(dp[i]!=-1)
    return dp[i];
    long min=1000000000;
    for(int j=i+1;j<=i+k;j++){
      long cost;
      if(j<=a.length-1){
      cost=Math.abs(a[i]-a[j])+go(a,j,k);
      min=Math.min(cost,min);
      dp[i]=min;
      }
    }
    return dp[i];
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int k=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextLong();
    }
    dp[n]=-1;
    System.out.print(go(a,0,k));
  }
}