import java.util.*;
public class Main {
  
 public static void main(String args[]){
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 }
} import java.util.*; util.* java public class Main {
  
 public static void main(String args[]){
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 }
} Main public static void main(String args[]){
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 } main {
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 } int N=0 N 0 k=0; k 0 Scanner obj=new Scanner(System.in); obj new Scanner(System.in) N=obj.nextInt() N obj.nextInt() obj.nextInt obj k=obj.nextInt() k obj.nextInt() obj.nextInt obj int h[]=new int[N]; h new int[N] N for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   } int i=0; int i=0; i 0 i<N i N i++ i++ i {
    h[i]=obj.nextInt();
   } {
    h[i]=obj.nextInt();
   } h[i]=obj.nextInt() h[i] h i obj.nextInt() obj.nextInt obj int dp[]=new int[N]; dp new int[N] N if(N==0)
      {
System.out.println(0);
return;
} N==0 N 0 {
System.out.println(0);
return;
} System.out.println(0) System.out.println System.out System System.out 0 return; if(N==1)
{     	
System.out.println(0);
return;
} N==1 N 1 {     	
System.out.println(0);
return;
} System.out.println(0) System.out.println System.out System System.out 0 return; if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
} N<=k+1 N k+1 k 1 {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
} System.out.println(Math.abs(h[0]-h[N-1])) System.out.println System.out System System.out Math.abs(h[0]-h[N-1]) Math.abs Math h[0]-h[N-1] h[0] h 0 h[N-1] h N-1 N 1 return; dp[0]=0 dp[0] dp 0 0 for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   } int i=1; int i=1; i 1 i<N i N i++ i++ i {
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   } {
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   } dp[i]=Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
} int j =1; int j =1; j 1 j<=i && j <=k j<=i j i j <=k j k j++ j++ j {
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
} {
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
} dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]) dp[i] dp i Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]) Math.min Math Math.abs(h[i]-h[i-j])+dp[i-j] Math.abs(h[i]-h[i-j]) Math.abs Math h[i]-h[i-j] h[i] h i h[i-j] h i-j i j dp[i-j] dp i-j i 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 args[] args public class Main {
  
 public static void main(String args[]){
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 }
} public class Main {
  
 public static void main(String args[]){
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 }
} Main
import java.util.*;
public class Main {
  
 public static void main(String args[]){
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 }
}
