//package EducationalDPContest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
        
        int[] nextIntArray(int n)
        {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        }
    } 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int a[]=sc.nextIntArray(n);
		
		
		//Now we have two changing variables n and k;
		//for each i we have k choices;
		//I need to reach from 0 to end;
		int dp[]=new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		//cost to reach 0 will be 0 only;
		dp[0]=0;
		
		for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		}
		System.out.println(dp[n-1]);

	}
	
	

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main {
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
        
        int[] nextIntArray(int n)
        {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        }
    } 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int a[]=sc.nextIntArray(n);
		
		
		//Now we have two changing variables n and k;
		//for each i we have k choices;
		//I need to reach from 0 to end;
		int dp[]=new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		//cost to reach 0 will be 0 only;
		dp[0]=0;
		
		for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		}
		System.out.println(dp[n-1]);

	}
	
	

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int a[]=sc.nextIntArray(n);
		
		
		//Now we have two changing variables n and k;
		//for each i we have k choices;
		//I need to reach from 0 to end;
		int dp[]=new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		//cost to reach 0 will be 0 only;
		dp[0]=0;
		
		for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		}
		System.out.println(dp[n-1]);

	} main {
		// TODO Auto-generated method stub
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int a[]=sc.nextIntArray(n);
		
		
		//Now we have two changing variables n and k;
		//for each i we have k choices;
		//I need to reach from 0 to end;
		int dp[]=new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		//cost to reach 0 will be 0 only;
		dp[0]=0;
		
		for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		}
		System.out.println(dp[n-1]);

	} FastReader sc=new FastReader(); sc new FastReader() int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int k=sc.nextInt(); k sc.nextInt() sc.nextInt sc int a[]=sc.nextIntArray(n); a sc.nextIntArray(n) sc.nextIntArray sc n int dp[]=new int[n+1]; dp new int[n+1] n+1 n 1 Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0]=0 dp[0] dp 0 0 for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		} {
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		} for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<=i+k j i+k i k j++ j++ j {
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			} {
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			} if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				} j<n j n {
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				} int cost=Math.abs(a[j]-a[i])+dp[i]; cost Math.abs(a[j]-a[i])+dp[i] Math.abs(a[j]-a[i]) Math.abs Math a[j]-a[i] a[j] a j a[i] a i dp[i] dp i dp[j]=Math.min(dp[j],cost) dp[j] dp j Math.min(dp[j],cost) Math.min Math dp[j] dp j cost 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 static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
        
        int[] nextIntArray(int n)
        {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        }
    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } FastReader { 
            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 int[] nextIntArray(int n)
        {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        } nextIntArray {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        } int a[]=new int[n]; a new int[n] n for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
        		a[i]=Integer.parseInt(next()); 
        	} {
        		a[i]=Integer.parseInt(next()); 
        	} a[i]=Integer.parseInt(next()) a[i] a i Integer.parseInt(next()) Integer.parseInt Integer next() next return a; a int n n public class Main {
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
        
        int[] nextIntArray(int n)
        {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        }
    } 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int a[]=sc.nextIntArray(n);
		
		
		//Now we have two changing variables n and k;
		//for each i we have k choices;
		//I need to reach from 0 to end;
		int dp[]=new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		//cost to reach 0 will be 0 only;
		dp[0]=0;
		
		for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		}
		System.out.println(dp[n-1]);

	}
	
	

} public class Main {
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
        
        int[] nextIntArray(int n)
        {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        }
    } 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int a[]=sc.nextIntArray(n);
		
		
		//Now we have two changing variables n and k;
		//for each i we have k choices;
		//I need to reach from 0 to end;
		int dp[]=new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		//cost to reach 0 will be 0 only;
		dp[0]=0;
		
		for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		}
		System.out.println(dp[n-1]);

	}
	
	

} Main
//package EducationalDPContest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            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; 
        } 
        
        int[] nextIntArray(int n)
        {
        	int a[]=new int[n];
        	for(int i=0;i<n;i++)
        	{
        		a[i]=Integer.parseInt(next()); 
        	}
        	return a;
        }
    } 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		int k=sc.nextInt();
		int a[]=sc.nextIntArray(n);
		
		
		//Now we have two changing variables n and k;
		//for each i we have k choices;
		//I need to reach from 0 to end;
		int dp[]=new int[n+1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		//cost to reach 0 will be 0 only;
		dp[0]=0;
		
		for(int i=0;i<n;i++)
		{
			//now to cost to reach 1; 
			//dp[i];
			//we can take k steps;
			//we are already at i;
			for(int j=i+1;j<=i+k;j++)
			{
				if(j<n)
				{
					int cost=Math.abs(a[j]-a[i])+dp[i];
					dp[j]=Math.min(dp[j],cost);
				}
			}
		}
		System.out.println(dp[n-1]);

	}
	
	

}
