import java.util.*;

class Main{
	static int []segmentTree;

	static void build(int []nums) {
		int n = nums.length;
		for (int i=0; i<n; i++)
			segmentTree[n+i] = nums[i];
		for (int i=n-1; i>0; i--) {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		}
	}

	static int query(int l, int r, int n) {
		int sum = 0;
		for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		}
		return sum;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n, k;
		n = in.nextInt();
		k = in.nextInt();
		int []nums = new int[n];
		for (int i=0; i<n; i++) nums[i] = in.nextInt();
		int dp[] = new int[n+1];
		for (int i=1; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		}
		// for (int i=0; i<n; i++)
		// 	System.out.print(dp[i]+" ");
		// System.out.println();
		System.out.println(dp[n-1]);
	}
} import java.util.*; util.* java class Main{
	static int []segmentTree;

	static void build(int []nums) {
		int n = nums.length;
		for (int i=0; i<n; i++)
			segmentTree[n+i] = nums[i];
		for (int i=n-1; i>0; i--) {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		}
	}

	static int query(int l, int r, int n) {
		int sum = 0;
		for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		}
		return sum;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n, k;
		n = in.nextInt();
		k = in.nextInt();
		int []nums = new int[n];
		for (int i=0; i<n; i++) nums[i] = in.nextInt();
		int dp[] = new int[n+1];
		for (int i=1; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		}
		// for (int i=0; i<n; i++)
		// 	System.out.print(dp[i]+" ");
		// System.out.println();
		System.out.println(dp[n-1]);
	}
} Main static int []segmentTree; segmentTree static void build(int []nums) {
		int n = nums.length;
		for (int i=0; i<n; i++)
			segmentTree[n+i] = nums[i];
		for (int i=n-1; i>0; i--) {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		}
	} build {
		int n = nums.length;
		for (int i=0; i<n; i++)
			segmentTree[n+i] = nums[i];
		for (int i=n-1; i>0; i--) {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		}
	} int n = nums.length; n nums.length nums nums.length for (int i=0; i<n; i++)
			segmentTree[n+i] = nums[i]; int i=0; int i=0; i 0 i<n i n i++ i++ i segmentTree[n+i] = nums[i]; segmentTree[n+i] = nums[i] segmentTree[n+i] segmentTree n+i n i nums[i] nums i for (int i=n-1; i>0; i--) {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		} int i=n-1; int i=n-1; i n-1 n 1 i>0 i 0 i-- i-- i {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		} {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		} segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1] segmentTree[i] segmentTree i segmentTree[2*i] + segmentTree[2*i+1] segmentTree[2*i] segmentTree 2*i 2 i segmentTree[2*i+1] segmentTree 2*i+1 2*i 2 i 1 int []nums nums static int query(int l, int r, int n) {
		int sum = 0;
		for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		}
		return sum;
	} query {
		int sum = 0;
		for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		}
		return sum;
	} int sum = 0; sum 0 for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		} l+=n, r+=n; l+=n l n r+=n r n l<r l r l>>=1, r>>=1 l>>=1 l 1 r>>=1 r 1 {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		} {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		} if ((l&1) == 1) {
				sum += segmentTree[l++];
			} (l&1) == 1 (l&1) l 1 1 {
				sum += segmentTree[l++];
			} sum += segmentTree[l++] sum segmentTree[l++] segmentTree l++ l if ((r&1) == 1) {
				sum += segmentTree[--r];
			} (r&1) == 1 (r&1) r 1 1 {
				sum += segmentTree[--r];
			} sum += segmentTree[--r] sum segmentTree[--r] segmentTree --r r return sum; sum int l l int r r int n n public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n, k;
		n = in.nextInt();
		k = in.nextInt();
		int []nums = new int[n];
		for (int i=0; i<n; i++) nums[i] = in.nextInt();
		int dp[] = new int[n+1];
		for (int i=1; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		}
		// for (int i=0; i<n; i++)
		// 	System.out.print(dp[i]+" ");
		// System.out.println();
		System.out.println(dp[n-1]);
	} main {
		Scanner in = new Scanner(System.in);
		int n, k;
		n = in.nextInt();
		k = in.nextInt();
		int []nums = new int[n];
		for (int i=0; i<n; i++) nums[i] = in.nextInt();
		int dp[] = new int[n+1];
		for (int i=1; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		}
		// for (int i=0; i<n; i++)
		// 	System.out.print(dp[i]+" ");
		// System.out.println();
		System.out.println(dp[n-1]);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n n k; k n = in.nextInt() n in.nextInt() in.nextInt in k = in.nextInt() k in.nextInt() in.nextInt in int []nums = new int[n]; nums new int[n] n for (int i=0; i<n; i++) nums[i] = in.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i nums[i] = in.nextInt(); nums[i] = in.nextInt() nums[i] nums i in.nextInt() in.nextInt in int dp[] = new int[n+1]; dp new int[n+1] n+1 n 1 for (int i=1; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		} {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		} dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			} {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			} if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				} i-j >= 0 i-j i j 0 {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				} dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j])) dp[i] dp i Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j])) Math.min Math dp[i] dp i dp[i-j]+Math.abs(nums[i] - nums[i-j]) dp[i-j] dp i-j i j Math.abs(nums[i] - nums[i-j]) Math.abs Math nums[i] - nums[i-j] nums[i] nums i nums[i-j] nums i-j i j {
					break;
				} break; 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
import java.util.*;

class Main{
	static int []segmentTree;

	static void build(int []nums) {
		int n = nums.length;
		for (int i=0; i<n; i++)
			segmentTree[n+i] = nums[i];
		for (int i=n-1; i>0; i--) {
			segmentTree[i] = segmentTree[2*i] + segmentTree[2*i+1];
		}
	}

	static int query(int l, int r, int n) {
		int sum = 0;
		for (l+=n, r+=n; l<r; l>>=1, r>>=1) {
			if ((l&1) == 1) {
				sum += segmentTree[l++];
			}
			if ((r&1) == 1) {
				sum += segmentTree[--r];
			}
		}
		return sum;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n, k;
		n = in.nextInt();
		k = in.nextInt();
		int []nums = new int[n];
		for (int i=0; i<n; i++) nums[i] = in.nextInt();
		int dp[] = new int[n+1];
		for (int i=1; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
			for (int j=1; j<=k; j++) {
				if (i-j >= 0) {
					// System.out.println(dp[i]+" "+(dp[i-j]+Math.abs(nums[i] - nums[i-j])));
					dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(nums[i] - nums[i-j]));
				}
				else {
					break;
				}
			}
		}
		// for (int i=0; i<n; i++)
		// 	System.out.print(dp[i]+" ");
		// System.out.println();
		System.out.println(dp[n-1]);
	}
}