
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    static int[] dp;
    static int min(int[]h,int ind,int k)
    {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    }
} import java.io.*; io.* java import java.math.*; math.* java import java.security.*; security.* java import java.text.*; text.* java import java.util.*; util.* java import java.util.concurrent.*; concurrent.* java.util import java.util.regex.*; regex.* java.util public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    static int[] dp;
    static int min(int[]h,int ind,int k)
    {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    }
} Main static BufferedReader br; br static long mod=1000000007; mod 1000000007 static int[] dp; dp static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	} cin {
		return Integer.valueOf(br.readLine());
	} return Integer.valueOf(br.readLine()); Integer.valueOf(br.readLine()) Integer.valueOf Integer br.readLine() br.readLine br static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} split {
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} String[] cmd=br.readLine().split(" "); cmd br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] ans=new int[cmd.length]; ans new int[cmd.length] cmd.length cmd cmd.length for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		} int i=0; int i=0; i 0 i<cmd.length i cmd.length cmd cmd.length i++ i++ i {
			ans[i]=Integer.valueOf(cmd[i]);
		} {
			ans[i]=Integer.valueOf(cmd[i]);
		} ans[i]=Integer.valueOf(cmd[i]) ans[i] ans i Integer.valueOf(cmd[i]) Integer.valueOf Integer cmd[i] cmd i return ans; ans static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } power { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } long res = 1; res 1 x = x % mod x x % mod x mod while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } y > 0 y 0 { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } if (y % 2 == 1) 
                res = (res * x) % mod; y % 2 == 1 y % 2 y 2 1 res = (res * x) % mod res (res * x) % mod (res * x) res x mod y = y >> 1 y y >> 1 y 1 x = (x * x) % mod x (x * x) % mod (x * x) x x mod return res%mod; res%mod res mod long x x long y y static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } modInverse { 
        return power(n, mod-2); 
    } return power(n, mod-2); power(n, mod-2) power n mod-2 mod 2 long n n static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    } digits {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    } int ans=0; ans 0 while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	} n!=0 n 0 {
    		ans++;
    		n=n/10;
    	} ans++ ans n=n/10 n n/10 n 10 return ans; ans int n n static int min(int[]h,int ind,int k)
    {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    } min {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    } if(ind==h.length-1)
    		return 0; ind==h.length-1 ind h.length-1 h.length h h.length 1 return 0; 0 if(ind>=h.length)
    		return 1000000000; ind>=h.length ind h.length h h.length return 1000000000; 1000000000 if(dp[ind]!=-1)
    		return dp[ind]; dp[ind]!=-1 dp[ind] dp ind -1 1 return dp[ind]; dp[ind] dp ind int res=1000000000; res 1000000000 for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	} int i=1; int i=1; i 1 i<=k i k i++ i++ i {
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	} {
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	} if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k)); ind+i<h.length ind+i ind i h.length h h.length res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k)) res Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k)) Math.min Math res Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k) Math.abs(h[ind+i]-h[ind]) Math.abs Math h[ind+i]-h[ind] h[ind+i] h ind+i ind i h[ind] h ind min(h,ind+i,k) min h ind+i ind i k dp[ind]=res dp[ind] dp ind res return res; res int[]h h int ind ind int k k public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    } main {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    } br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) int[]ar=split(); ar split() split int n=ar[0]; n ar[0] ar 0 int k=ar[1]; k ar[1] ar 1 int[]h=split(); h split() split dp=new int[n+1] dp new int[n+1] n+1 n 1 Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 System.out.println(min(h,0,k)) System.out.println System.out System System.out min(h,0,k) min h 0 k String[] args args public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    static int[] dp;
    static int min(int[]h,int ind,int k)
    {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    }
} public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    static int[] dp;
    static int min(int[]h,int ind,int k)
    {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    }
} Main

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    static int[] dp;
    static int min(int[]h,int ind,int k)
    {
    	if(ind==h.length-1)
    		return 0;
    	if(ind>=h.length)
    		return 1000000000;
    	if(dp[ind]!=-1)
    		return dp[ind];
    	int res=1000000000;
    	for(int i=1;i<=k;i++)
    	{
    		if(ind+i<h.length)
    			res=Math.min(res,Math.abs(h[ind+i]-h[ind])+min(h,ind+i,k));
    	}
    	dp[ind]=res;
    	return res;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int[]ar=split();
        int n=ar[0];
        int k=ar[1];
        int[]h=split();
        dp=new int[n+1];
        Arrays.fill(dp, -1);
        System.out.println(min(h,0,k));
    }
}