//package godiji;

import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;

public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	static ArrayList<String>list=new ArrayList<String>();
	
	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;
		}
	}

	static FastReader s = new FastReader();

	public static void main(String[] args) {
		
		int n=scn.nextInt(),k=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=scn.nextInt();
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println((int)frog(arr, k, 0,memo));
		
		
	}
	public static long frog(int arr[],int k,int ind,long memo[])
	{if(ind==arr.length-1)
		return 0;
	if(ind>=arr.length)
		return Integer.MAX_VALUE;
	if(memo[ind]!=-1)
		return memo[ind];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		}
		memo[ind]=a;
		return a;
	}
	public static boolean[] sieveOfEratosthenes(int n) {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	}

	public static long string(int n, String str, long memo[]) {
		if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		}

		long a = (string(n, str + "0", memo)) % mod;
		long b = (string(n, str + "1", memo)) % mod;
		return (a + b) % mod;
	}

	public static long gcd(long a, long n) {

		if (a == 0)
			return n;
		return gcd(n % a, a);
	}

	public static long lcm(long a, long b) {
		long s = (a * b) / gcd(a, b);
		return s;
	}
}

class pair {
	int x;
	int y;

	pair(int a, int b) {
		this.x = a;
		this.y = b;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub

		
			return 0;
	}

} import java.util.Scanner; Scanner java.util import java.util.Stack; Stack java.util import java.util.StringTokenizer; StringTokenizer java.util import java.util.TreeMap; TreeMap java.util import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.math.BigInteger; BigInteger java.math import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.Iterator; Iterator java.util import java.util.PriorityQueue; PriorityQueue java.util public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	static ArrayList<String>list=new ArrayList<String>();
	
	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;
		}
	}

	static FastReader s = new FastReader();

	public static void main(String[] args) {
		
		int n=scn.nextInt(),k=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=scn.nextInt();
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println((int)frog(arr, k, 0,memo));
		
		
	}
	public static long frog(int arr[],int k,int ind,long memo[])
	{if(ind==arr.length-1)
		return 0;
	if(ind>=arr.length)
		return Integer.MAX_VALUE;
	if(memo[ind]!=-1)
		return memo[ind];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		}
		memo[ind]=a;
		return a;
	}
	public static boolean[] sieveOfEratosthenes(int n) {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	}

	public static long string(int n, String str, long memo[]) {
		if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		}

		long a = (string(n, str + "0", memo)) % mod;
		long b = (string(n, str + "1", memo)) % mod;
		return (a + b) % mod;
	}

	public static long gcd(long a, long n) {

		if (a == 0)
			return n;
		return gcd(n % a, a);
	}

	public static long lcm(long a, long b) {
		long s = (a * b) / gcd(a, b);
		return s;
	}
} Main static Scanner scn = new Scanner(System.in); scn new Scanner(System.in) static int mod = 1000000007; mod 1000000007 static ArrayList<String>list=new ArrayList<String>(); list new ArrayList<String>() static FastReader s = new FastReader(); s new FastReader() public static void main(String[] args) {
		
		int n=scn.nextInt(),k=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=scn.nextInt();
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println((int)frog(arr, k, 0,memo));
		
		
	} main {
		
		int n=scn.nextInt(),k=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=scn.nextInt();
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println((int)frog(arr, k, 0,memo));
		
		
	} int n=scn.nextInt() n scn.nextInt() scn.nextInt scn k=scn.nextInt(); k scn.nextInt() scn.nextInt scn int arr[]=new int[n]; arr new int[n] n for(int i=0;i<n;i++)
			arr[i]=scn.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i]=scn.nextInt(); arr[i]=scn.nextInt() arr[i] arr i scn.nextInt() scn.nextInt scn long memo[]=new long[n+1]; memo new long[n+1] n+1 n 1 Arrays.fill(memo, -1) Arrays.fill Arrays memo -1 1 System.out.println((int)frog(arr, k, 0,memo)) System.out.println System.out System System.out (int)frog(arr, k, 0,memo) frog arr k 0 memo String[] args args public static long frog(int arr[],int k,int ind,long memo[])
	{if(ind==arr.length-1)
		return 0;
	if(ind>=arr.length)
		return Integer.MAX_VALUE;
	if(memo[ind]!=-1)
		return memo[ind];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		}
		memo[ind]=a;
		return a;
	} frog {if(ind==arr.length-1)
		return 0;
	if(ind>=arr.length)
		return Integer.MAX_VALUE;
	if(memo[ind]!=-1)
		return memo[ind];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		}
		memo[ind]=a;
		return a;
	} if(ind==arr.length-1)
		return 0; ind==arr.length-1 ind arr.length-1 arr.length arr arr.length 1 return 0; 0 if(ind>=arr.length)
		return Integer.MAX_VALUE; ind>=arr.length ind arr.length arr arr.length return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE if(memo[ind]!=-1)
		return memo[ind]; memo[ind]!=-1 memo[ind] memo ind -1 1 return memo[ind]; memo[ind] memo ind long a=Integer.MAX_VALUE a Integer.MAX_VALUE Integer Integer.MAX_VALUE b=Integer.MAX_VALUE; b Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		} int i=1; int i=1; i 1 i<=k i k i++ i++ i {
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		} {
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		} b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]) b frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]) frog(arr, k, ind+i,memo) frog arr k ind+i ind i memo Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]) Math.abs Math arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)] arr[Math.min(ind+i, arr.length-1)] arr Math.min(ind+i, arr.length-1) Math.min Math ind+i ind i arr.length-1 arr.length arr arr.length 1 arr[Math.min(ind,arr.length-1)] arr Math.min(ind,arr.length-1) Math.min Math ind arr.length-1 arr.length arr arr.length 1 a=Math.min(a, b) a Math.min(a, b) Math.min Math a b memo[ind]=a memo[ind] memo ind a return a; a int arr[] arr int k k int ind ind long memo[] memo public static boolean[] sieveOfEratosthenes(int n) {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	} sieveOfEratosthenes {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	} boolean prime[] = new boolean[n + 1]; prime new boolean[n + 1] n + 1 n 1 for (int i = 0; i < n; i++)
			prime[i] = true; int i = 0; int i = 0; i 0 i < n i n i++ i++ i prime[i] = true; prime[i] = true prime[i] prime i true for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		} int p = 2; int p = 2; p 2 p * p <= n p * p p p n p++ p++ p {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		} {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		} if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			} prime[p] == true prime[p] prime p true {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			} for (int i = p * p; i <= n; i += p)
					prime[i] = false; int i = p * p; int i = p * p; i p * p p p i <= n i n i += p i += p i p prime[i] = false; prime[i] = false prime[i] prime i false for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		} int i = 2; int i = 2; i 2 i <= n i n i++ i++ i {
			if (prime[i] == true) {
				// list.add(i);
			}

		} {
			if (prime[i] == true) {
				// list.add(i);
			}

		} if (prime[i] == true) {
				// list.add(i);
			} prime[i] == true prime[i] prime i true {
				// list.add(i);
			} return prime; prime int n n public static long string(int n, String str, long memo[]) {
		if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		}

		long a = (string(n, str + "0", memo)) % mod;
		long b = (string(n, str + "1", memo)) % mod;
		return (a + b) % mod;
	} string {
		if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		}

		long a = (string(n, str + "0", memo)) % mod;
		long b = (string(n, str + "1", memo)) % mod;
		return (a + b) % mod;
	} if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		} str.length() == n str.length() str.length str n {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		} boolean bl = true; bl true for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			} {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			} if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				} str.charAt(i) == '1' && str.charAt(i + 1) == '1' str.charAt(i) == '1' str.charAt(i) str.charAt str i '1' str.charAt(i + 1) == '1' str.charAt(i + 1) str.charAt str i + 1 i 1 '1' {
					bl = false;
					break;
				} bl = false bl false break; if (bl)
				return 1;
			else
				return 0; bl return 1; 1 return 0; 0 long a = (string(n, str + "0", memo)) % mod; a (string(n, str + "0", memo)) % mod (string(n, str + "0", memo)) string n str + "0" str "0" memo mod long b = (string(n, str + "1", memo)) % mod; b (string(n, str + "1", memo)) % mod (string(n, str + "1", memo)) string n str + "1" str "1" memo mod return (a + b) % mod; (a + b) % mod (a + b) a b mod int n n String str str long memo[] memo public static long gcd(long a, long n) {

		if (a == 0)
			return n;
		return gcd(n % a, a);
	} gcd {

		if (a == 0)
			return n;
		return gcd(n % a, a);
	} if (a == 0)
			return n; a == 0 a 0 return n; n return gcd(n % a, a); gcd(n % a, a) gcd n % a n a a long a a long n n public static long lcm(long a, long b) {
		long s = (a * b) / gcd(a, b);
		return s;
	} lcm {
		long s = (a * b) / gcd(a, b);
		return s;
	} long s = (a * b) / gcd(a, b); s (a * b) / gcd(a, b) (a * b) a b gcd(a, b) gcd a b return s; s long a a long b b 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;
		}
	} 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 class pair {
	int x;
	int y;

	pair(int a, int b) {
		this.x = a;
		this.y = b;
	}
} pair int x; x int y; y pair(int a, int b) {
		this.x = a;
		this.y = b;
	} pair {
		this.x = a;
		this.y = b;
	} this.x = a this.x this this.x a this.y = b this.y this this.y b int a a int b b class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub

		
			return 0;
	}

} sorting @Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub

		
			return 0;
	} compare {
		// TODO Auto-generated method stub

		
			return 0;
	} return 0; 0 pair o1 o1 pair o2 o2 Comparator public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	static ArrayList<String>list=new ArrayList<String>();
	
	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;
		}
	}

	static FastReader s = new FastReader();

	public static void main(String[] args) {
		
		int n=scn.nextInt(),k=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=scn.nextInt();
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println((int)frog(arr, k, 0,memo));
		
		
	}
	public static long frog(int arr[],int k,int ind,long memo[])
	{if(ind==arr.length-1)
		return 0;
	if(ind>=arr.length)
		return Integer.MAX_VALUE;
	if(memo[ind]!=-1)
		return memo[ind];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		}
		memo[ind]=a;
		return a;
	}
	public static boolean[] sieveOfEratosthenes(int n) {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	}

	public static long string(int n, String str, long memo[]) {
		if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		}

		long a = (string(n, str + "0", memo)) % mod;
		long b = (string(n, str + "1", memo)) % mod;
		return (a + b) % mod;
	}

	public static long gcd(long a, long n) {

		if (a == 0)
			return n;
		return gcd(n % a, a);
	}

	public static long lcm(long a, long b) {
		long s = (a * b) / gcd(a, b);
		return s;
	}
} public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	static ArrayList<String>list=new ArrayList<String>();
	
	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;
		}
	}

	static FastReader s = new FastReader();

	public static void main(String[] args) {
		
		int n=scn.nextInt(),k=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=scn.nextInt();
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println((int)frog(arr, k, 0,memo));
		
		
	}
	public static long frog(int arr[],int k,int ind,long memo[])
	{if(ind==arr.length-1)
		return 0;
	if(ind>=arr.length)
		return Integer.MAX_VALUE;
	if(memo[ind]!=-1)
		return memo[ind];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		}
		memo[ind]=a;
		return a;
	}
	public static boolean[] sieveOfEratosthenes(int n) {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	}

	public static long string(int n, String str, long memo[]) {
		if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		}

		long a = (string(n, str + "0", memo)) % mod;
		long b = (string(n, str + "1", memo)) % mod;
		return (a + b) % mod;
	}

	public static long gcd(long a, long n) {

		if (a == 0)
			return n;
		return gcd(n % a, a);
	}

	public static long lcm(long a, long b) {
		long s = (a * b) / gcd(a, b);
		return s;
	}
} Main
//package godiji;

import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;

public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	static ArrayList<String>list=new ArrayList<String>();
	
	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;
		}
	}

	static FastReader s = new FastReader();

	public static void main(String[] args) {
		
		int n=scn.nextInt(),k=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=scn.nextInt();
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println((int)frog(arr, k, 0,memo));
		
		
	}
	public static long frog(int arr[],int k,int ind,long memo[])
	{if(ind==arr.length-1)
		return 0;
	if(ind>=arr.length)
		return Integer.MAX_VALUE;
	if(memo[ind]!=-1)
		return memo[ind];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int i=1;i<=k;i++)
		{
			b=frog(arr, k, ind+i,memo)+Math.abs(arr[Math.min(ind+i, arr.length-1)]-arr[Math.min(ind,arr.length-1)]);
			a=Math.min(a, b);
		}
		memo[ind]=a;
		return a;
	}
	public static boolean[] sieveOfEratosthenes(int n) {

		boolean prime[] = new boolean[n + 1];
		for (int i = 0; i < n; i++)
			prime[i] = true;

		for (int p = 2; p * p <= n; p++) {
			// If prime[p] is not changed, then it is a prime
			if (prime[p] == true) {
				// Update all multiples of p
				for (int i = p * p; i <= n; i += p)
					prime[i] = false;
			}
		}

		for (int i = 2; i <= n; i++) {
			if (prime[i] == true) {
				// list.add(i);
			}

		}
		return prime;
	}

	public static long string(int n, String str, long memo[]) {
		if (str.length() == n) {
			boolean bl = true;
			for (int i = 0; i < n - 1; i++) {
				if (str.charAt(i) == '1' && str.charAt(i + 1) == '1') {
					bl = false;
					break;
				}
			}
			if (bl)
				return 1;
			else
				return 0;
		}

		long a = (string(n, str + "0", memo)) % mod;
		long b = (string(n, str + "1", memo)) % mod;
		return (a + b) % mod;
	}

	public static long gcd(long a, long n) {

		if (a == 0)
			return n;
		return gcd(n % a, a);
	}

	public static long lcm(long a, long b) {
		long s = (a * b) / gcd(a, b);
		return s;
	}
}

class pair {
	int x;
	int y;

	pair(int a, int b) {
		this.x = a;
		this.y = b;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub

		
			return 0;
	}

}
