#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
// your code goes here
ll n,k;
cin>>n;
cin>>k;
ll i=1;
ll b[n+1]={0};
while(i<=n)
{
cin>>b[i];
i++;
}
ll dp[n+1]={0};
dp[1]=0;
dp[2]=abs(b[1]-b[2]);
i=3;
while(i<=n)
{
ll answer=INT_MAX;
ll j =1;
while(j<=k&& i-j>=1)
{
ll option = abs(b[i-j]-b[i])+dp[i-j];
answer = min(option,answer);
j++;
}
dp[i]=answer;
i++;
//cout<<i<<" "<<dp[i]<<"\n";
}
cout<<dp[n];
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKCgppbnQgbWFpbigpIHsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCWxsIG4sazsKCWNpbj4+bjsKCWNpbj4+azsKCWxsIGk9MTsKCWxsIGJbbisxXT17MH07Cgl3aGlsZShpPD1uKQoJIHsKCSAJY2luPj5iW2ldOwoJIAlpKys7CgkgfQoJIAoJIAoJIGxsIGRwW24rMV09ezB9OwoJIGRwWzFdPTA7CgkgZHBbMl09YWJzKGJbMV0tYlsyXSk7CgkgCgkgaT0zOwoJIHdoaWxlKGk8PW4pCgkgIHsKCSAgCWxsIGFuc3dlcj1JTlRfTUFYOwoJICAJbGwgaiA9MTsKCSAgCXdoaWxlKGo8PWsmJiBpLWo+PTEpCgkgIAkgewoJICAJIAlsbCBvcHRpb24gPSBhYnMoYltpLWpdLWJbaV0pK2RwW2ktal07CgkgIAkgCWFuc3dlciA9IG1pbihvcHRpb24sYW5zd2VyKTsKCSAgCSAJaisrOwoJICAJIH0KCSAgCWRwW2ldPWFuc3dlcjsKCSAgCWkrKzsKCSAgCS8vY291dDw8aTw8IiAiPDxkcFtpXTw8IlxuIjsKCSAgCQoJICB9CgkgIAoJICBjb3V0PDxkcFtuXTsKCQoJcmV0dXJuIDA7Cgp9