
import java.io.*;
import java.util.*;
class Main {
	public static void main (String[] args) {
		//System.out.println("GfG!");
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k = sc.nextInt();
		int a[]=new int[n+1];
		a[0]=0;
		for(int i=1;i<=n;i++)
		a[i]=sc.nextInt();
	    int dp[]=new int[n+1];
	    dp[0]=0;
	    dp[1]=0;
	    if(k+1>=n)
	    System.out.println(Math.abs(a[n]-a[1]));
	    else{
	    for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    }
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    }
	    	    System.out.println(dp[n]);}
	}
} import java.io.*; io.* java import java.util.*; util.* java class Main {
	public static void main (String[] args) {
		//System.out.println("GfG!");
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k = sc.nextInt();
		int a[]=new int[n+1];
		a[0]=0;
		for(int i=1;i<=n;i++)
		a[i]=sc.nextInt();
	    int dp[]=new int[n+1];
	    dp[0]=0;
	    dp[1]=0;
	    if(k+1>=n)
	    System.out.println(Math.abs(a[n]-a[1]));
	    else{
	    for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    }
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    }
	    	    System.out.println(dp[n]);}
	}
} Main public static void main (String[] args) {
		//System.out.println("GfG!");
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k = sc.nextInt();
		int a[]=new int[n+1];
		a[0]=0;
		for(int i=1;i<=n;i++)
		a[i]=sc.nextInt();
	    int dp[]=new int[n+1];
	    dp[0]=0;
	    dp[1]=0;
	    if(k+1>=n)
	    System.out.println(Math.abs(a[n]-a[1]));
	    else{
	    for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    }
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    }
	    	    System.out.println(dp[n]);}
	} main {
		//System.out.println("GfG!");
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k = sc.nextInt();
		int a[]=new int[n+1];
		a[0]=0;
		for(int i=1;i<=n;i++)
		a[i]=sc.nextInt();
	    int dp[]=new int[n+1];
	    dp[0]=0;
	    dp[1]=0;
	    if(k+1>=n)
	    System.out.println(Math.abs(a[n]-a[1]));
	    else{
	    for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    }
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    }
	    	    System.out.println(dp[n]);}
	} 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 a[]=new int[n+1]; a new int[n+1] n+1 n 1 a[0]=0 a[0] a 0 0 for(int i=1;i<=n;i++)
		a[i]=sc.nextInt(); int i=1; int i=1; i 1 i<=n i n i++ i++ i a[i]=sc.nextInt(); a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int dp[]=new int[n+1]; dp new int[n+1] n+1 n 1 dp[0]=0 dp[0] dp 0 0 dp[1]=0 dp[1] dp 1 0 if(k+1>=n)
	    System.out.println(Math.abs(a[n]-a[1]));
	    else{
	    for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    }
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    }
	    	    System.out.println(dp[n]);} k+1>=n k+1 k 1 n System.out.println(Math.abs(a[n]-a[1])) System.out.println System.out System System.out Math.abs(a[n]-a[1]) Math.abs Math a[n]-a[1] a[n] a n a[1] a 1 {
	    for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    }
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    }
	    	    System.out.println(dp[n]);} for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    } int i=2; int i=2; i 2 i<=(1+k) i (1+k) 1 k i++ i++ i {
	        dp[i]=Math.abs(a[i]-a[1]);
	    } {
	        dp[i]=Math.abs(a[i]-a[1]);
	    } dp[i]=Math.abs(a[i]-a[1]) dp[i] dp i Math.abs(a[i]-a[1]) Math.abs Math a[i]-a[1] a[i] a i a[1] a 1 dp[2]=Math.abs(a[2]-a[1]) dp[2] dp 2 Math.abs(a[2]-a[1]) Math.abs Math a[2]-a[1] a[2] a 2 a[1] a 1 for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    } int i=k+2; int i=k+2; i k+2 k 2 i<=n i n i++ i++ i {
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    } {
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    } int c = k; c k for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        } int j=1; int j=1; j 1 j<=c j c j++ j++ j {
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        } {
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        } if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            } j==1 j 1 {
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            } dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]) dp[i] dp i dp[i-j]+Math.abs(a[i]-a[i-j]) dp[i-j] dp i-j i j Math.abs(a[i]-a[i-j]) Math.abs Math a[i]-a[i-j] a[i] a i a[i-j] a i-j i j continue; dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]) dp[i] dp i Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]) Math.min Math dp[i-j]+Math.abs(a[i]-a[i-j]) dp[i-j] dp i-j i j Math.abs(a[i]-a[i-j]) Math.abs Math a[i]-a[i-j] a[i] a i a[i-j] a i-j i j dp[i] dp i System.out.println(dp[n]) System.out.println System.out System System.out dp[n] dp n String[] args args

import java.io.*;
import java.util.*;
class Main {
	public static void main (String[] args) {
		//System.out.println("GfG!");
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k = sc.nextInt();
		int a[]=new int[n+1];
		a[0]=0;
		for(int i=1;i<=n;i++)
		a[i]=sc.nextInt();
	    int dp[]=new int[n+1];
	    dp[0]=0;
	    dp[1]=0;
	    if(k+1>=n)
	    System.out.println(Math.abs(a[n]-a[1]));
	    else{
	    for(int i=2;i<=(1+k);i++){
	        dp[i]=Math.abs(a[i]-a[1]);
	    }
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=k+2;i<=n;i++){
	        int c = k;
	        for(int j=1;j<=c;j++){
	            if(j==1){
	                dp[i]=dp[i-j]+Math.abs(a[i]-a[i-j]);
	                continue;
	            }
	            dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	            
	        }
	    }
	    	    System.out.println(dp[n]);}
	}
}