//package codeforces;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;
import java.util.Set;

public class Main {
	// Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String[] args) {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	}

	public static long mincost(long arr[],int n,int i,int k,long memo[])
	{	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=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 class Pair implements Comparable {
		int x;
		int y;
		int z;

		Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		}

	}

} import java.util.Scanner; Scanner java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.LinkedList; LinkedList java.util import java.util.TreeMap; TreeMap java.util import java.util.TreeSet; TreeSet java.util 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.Stack; Stack java.util import java.util.Set; Set java.util public class Main {
	// Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String[] args) {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	}

	public static long mincost(long arr[],int n,int i,int k,long memo[])
	{	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=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 class Pair implements Comparable {
		int x;
		int y;
		int z;

		Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		}

	}

} Main // Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in); scn new Scanner(System.in) static int mod = 1000000007; mod 1000000007 public static void main(String[] args) {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	} main {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	} int n = scn.nextInt() n scn.nextInt() scn.nextInt scn k=scn.nextInt(); k scn.nextInt() scn.nextInt scn long arr[] = new long[n]; arr new long[n] n long memo[] = new long[n]; memo new long[n] n for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i arr[i] = scn.nextLong(); arr[i] = scn.nextLong() arr[i] arr i scn.nextLong() scn.nextLong scn if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		} k>=n k n System.out.println(Math.abs(arr[0]-arr[n-1])) System.out.println System.out System System.out Math.abs(arr[0]-arr[n-1]) Math.abs Math arr[0]-arr[n-1] arr[0] arr 0 arr[n-1] arr n-1 n 1 {
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		} Arrays.fill(memo,-1) Arrays.fill Arrays memo -1 1 System.out.println(mincost(arr, n, 0, k,memo)) System.out.println System.out System System.out mincost(arr, n, 0, k,memo) mincost arr n 0 k memo String[] args args public static long mincost(long arr[],int n,int i,int k,long memo[])
	{	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=a;
		}
		return a;
	} mincost {	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=a;
		}
		return a;
	} if(i==n-1)
		return 0; i==n-1 i n-1 n 1 return 0; 0 if(i>=n)
			return Integer.MAX_VALUE; i>=n i n return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE if(memo[i]!=-1)
			return memo[i]; memo[i]!=-1 memo[i] memo i -1 1 return memo[i]; memo[i] memo i 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 j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=a;
		} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=a;
		} {
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=a;
		} b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]) b mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]) mincost(arr, n, i+j, k,memo) mincost arr n i+j i j k memo Math.abs(arr[i]-arr[Math.min(n-1, i+j)]) Math.abs Math arr[i]-arr[Math.min(n-1, i+j)] arr[i] arr i arr[Math.min(n-1, i+j)] arr Math.min(n-1, i+j) Math.min Math n-1 n 1 i+j i j a=Math.min(a, b) a Math.min(a, b) Math.min Math a b memo[i]=a memo[i] memo i a return a; a long arr[] arr int n n int i i int k k 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 class Pair implements Comparable {
		int x;
		int y;
		int z;

		Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		}

	} Pair int x; x int y; y int z; z Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		} Pair {
			this.x = x;
			this.y = y;
			this.z = z;
		} this.x = x this.x this this.x x this.y = y this.y this this.y y this.z = z this.z this this.z z int x x int y y int z z public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		} compareTo {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		} Pair pp = (Pair) o; pp (Pair) o if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1; pp.x == x pp.x pp pp.x x return 0; 0 if (x > pp.x)
				return 1;
			else
				return -1; x > pp.x x pp.x pp pp.x return 1; 1 return -1; -1 1 Object o o Comparable public class Main {
	// Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String[] args) {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	}

	public static long mincost(long arr[],int n,int i,int k,long memo[])
	{	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=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 class Pair implements Comparable {
		int x;
		int y;
		int z;

		Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		}

	}

} public class Main {
	// Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String[] args) {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	}

	public static long mincost(long arr[],int n,int i,int k,long memo[])
	{	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=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 class Pair implements Comparable {
		int x;
		int y;
		int z;

		Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		}

	}

} Main
//package codeforces;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;
import java.util.Set;

public class Main {
	// Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String[] args) {
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		// code
		int n = scn.nextInt(),k=scn.nextInt();
		long arr[] = new long[n];
		long memo[] = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = scn.nextLong();
		if(k>=n)
			System.out.println(Math.abs(arr[0]-arr[n-1]));
		else
		{
		Arrays.fill(memo,-1);
		System.out.println(mincost(arr, n, 0, k,memo));
		}
		

	}

	public static long mincost(long arr[],int n,int i,int k,long memo[])
	{	if(i==n-1)
		return 0;
		if(i>=n)
			return Integer.MAX_VALUE;
		if(memo[i]!=-1)
			return memo[i];
		long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
		for(int j=1;j<=k;j++)
		{
			b=mincost(arr, n, i+j, k,memo)+Math.abs(arr[i]-arr[Math.min(n-1, i+j)]);	
			a=Math.min(a, b);
			memo[i]=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 class Pair implements Comparable {
		int x;
		int y;
		int z;

		Pair(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public int compareTo(Object o) {
			Pair pp = (Pair) o;
			if (pp.x == x)
				return 0;
			else if (x > pp.x)
				return 1;
			else
				return -1;
		}

	}

}
