#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<vector>
#define ll long long
#define mt(a) memset(a,0,sizeof(a))
#define MAXI 2000000000
#define PAI pair<int,int>

using namespace std;

int a[100009], dp[100009];
int main()
{
	int n,k;
	scanf("%d%d", &n,&k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		dp[i] = MAXI;
	}
	dp[1] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= min(n, i + k); j++)
			dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
	}
	printf("%d\n", dp[n]);


	return 0;
}