#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
const int N=1e5+5;
const int inf=1e9+7;
int dp[N],h[N];
int main(){
	int n,i,j,k;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>h[i];
	}
	for(i=2;i<=n;i++){
		dp[i]=inf;
		for(j=max(i-k,1);j<i;j++){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n];
}
