//                                                                                                         
//                    |    |                    |         ,---.     o               |    
//,---.,---.,---.,---.|---.|__/ ,---.,---.,---.' ,---.    `---.,---..,---.,---.,---.|--- 
//|---'|   ||    |   ||   ||  \ ,---||   |,---|  `---.        ||   |||   ||   ||---'|     
//`---'|---'`---'`   '`   '`   ``---^|---'`---^  `---'    `---'`   '`|---'|---'`---'`---'
//     |                             |                               |    |   
//								.    , '|      /|
//								|    |  |     / |
//								 \  /   |    /__|_ 
//								  `'    | o     |
//      Version 1.4 patchnotes{
//			New Feature: Dying for the river flowing
//			New defines: finding the max and min of three integers
//			New Poetry: Rose,violet
//			New quotes: Russian proverb
//			Bug fixes
//		}        
//
//In the name of Allah the beneficent, the merciful
//Here the Special Forces come
//I know a thing and it is that I dont know nothing
//One day all turks will be gone crazy, then god bless you
//There's no ugly women, there's less vodka
//Sub to Mcan
//
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
//
//_______________%%%%%%%%%%%%%%__________________________________
//_____________%%%%%%%%%%%%%%%%%_________________________________
//____________%%%%%%%%%%%%%%%%%%%________________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%______________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%%_____________________________
//________%%%%%%%%%%%%%%%_____%%%%%%%____________________________
//________%%%%%%%%%%%%___________%%%%____________________________
//_______%%%%%%%%%%%%_____________%%%%___________________________
//_______%%%%%%%%%%%_______________%%%___________________________
//______%%%%%%%%%%%_________________%%%_____%%___________________
//______%%%%%%%%%%__________________________%%%__________________
//______%%%%%%%%%___________________________%%%__________________
//_____%%%%%%%%%%___________________________%%%%_________________
//_____%%%%%%%%%____________________________%%%%%%%%%%%%_________
//_____%%%%%%%%%___________________________%%%%%%%%%%%___________
//_____%%%%%%%%%_________________________%%%%%%%%%%%%____________
//_____%%%%%%%%%_______________________%%%%%%%%%%%%%_____________
//_____%%%%%%%%%_____________________%%%%%%%%%%%%%%%_____________
//_____%%%%%%%%%_________________________%%%%%%%%%%%_____________
//_____%%%%%%%%%___________________________%%%%%%%%%%____________
//_____%%%%%%%%%%___________________________%%%%%%%%%%___________
//______%%%%%%%%%___________________________%%%%%%%%%%___________
//______%%%%%%%%%___________________________%%%%____%%%__________
//_______%%%%%%%%%__________________________%%%_______%%_________
//_______%%%%%%%%%%_________________%_______%%__________%________
//________%%%%%%%%%%_______________%%_______%____________________
//________%%%%%%%%%%%_____________%%%____________________________
//_________%%%%%%%%%%%%%________%%%%_____________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%______________________________
//___________%%%%%%%%%%%%%%%%%%%%%_______________________________
//____________%%%%%%%%%%%%%%%%%%%________________________________
//_____________%%%%%%%%%%%%%%%%%_________________________________
//______________%%%%%%%%%%%%%%%__________________________________
//_______________%%%%%%%%%%%%%___________________________________
//__________________%%%%%%%%_____________________________________
// _   __, _ __,   __,  _, __,   , _  _, _,_ __,   __, _ _,_ __, __,   __, _,   _, _  _ _ _, _  _,
// |   | \ | |_    |_  / \ |_)   \ | / \ | | |_)   |_) | | / |_  |_)   |_  |   / \ |  | | |\ | / _
// |   |_/ | |_    |   \ / | \    \| \ / |_| | \   | \ | |/  |   | \   |   | , \ / |/\| | | \| \ /
// ~   ~   ~ ~~~   ~    ~  ~ ~     )  ~  `~' ~ ~   ~ ~ ~ ~   ~~~ ~ ~   ~   ~~~  ~  ~  ~ ~ ~  ~  ~ 
//                                ~'                                                              
//
//        ⣠⣶⣾⣿⣿⢶⣶⡶⠦
//⠀⠀⠀⠀⠀⢀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢢
//⠀⠀⠀⠀⠀⢸⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡄

//⠀⠀⠀⠀⠀⢸⣿⠃⠀⢀⣠⣶⡆⢠⣶⣖⣻⣎⡇

//⠀⠀⠀⠀⠀⠁⡜⡄⠀⠉⠝⠋⠁⠘⣿⢿⡿⣳⠁

//⠀⠀⠀⠀⠀⠀⠀⣆⠀⠀⡠⠫⢤⣠⣿⡆⢘⡏

//⠀⠀⠀⠀⠀⠀⠀⣿⣦⡀⢧⣷⣬⢿⣽⣿⣾⠃

//⠀⠀⠀⢀⣴⣇⠙⣿⣿⣏⠚⠻⢿⣻⡿⠁

//⣤⣴⣶⣿⣿⣿⣿⣆⠈⠙⢿⣷⣾⣾⡿⣤⣤⣀

//⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠙⢿⠟⠁⣿⣿⣿⣿⣶⣄⡀

//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⣠⣾⣦⡀⠸⣿⣿⣿⣿⣿⣿⣧

//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠈⣿⣿⠃⠀⢿⣷⣿⣿⣿⣿⣿
//
//  __                                                             
// /  |                                                           |
//(___| ___  ___  ___  ___       ___  ___  ___       ___  ___  ___|
//|\   |   )|___ |___)|___      |   )|   )|___)     |   )|___)|   )
//| \  |__/  __/ |__   __/      |__/||    |__       |    |__  |__/ 
//                                                                 
//                                                                       
//|    |      /      /                                  /    /          
//(    )   ___ (  ___ (___  ___       ___  ___  ___      (___ (       ___ 
// \  /| |   )| |___)|    |___      |   )|   )|___)     |   )| |   )|___)
//  \/ | |__/ | |__  |__   __/      |__/||    |__       |__/ | |__/ |__  
//                                                                       
//
//  __                                                                                  __                  
// /|  /                   /                 /                                         /  |      /          
//( | (___  ___  ___  ___     ___       ___ (       ___       ___       ___  ___      (___| ___    ___  ___ 
//  | |   )|___)|   )|___)   |___      |   )| |   )|   )\   )|___      |   )|   )     |   )|___ | |   )|   )
//  | |  / |__  |    |__      __/      |__/|| |/\/ |__/| \_/  __/      |__/||  /      |  /  __/ | |__/||  / 
//                                                       /                                                 
//
//  __                                                                       
//|/  |      /    /                   /    /                                 
//|___| ___ (___ (___  ___  ___      (___ (___  ___  ___            ___      
//|   )|___)|    |    |___)|   )     |    |   )|   )|   )     \   )|   )|   )
//|__/ |__  |__  |__  |__  |         |__  |  / |__/||  /       \_/ |__/ |__/ 
//                                                             /            

//"Insert Problem name and code here"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define nl '\n'
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define fillar(x) for(int i=0;i<x;i++)cin>>ar[i]
#define qquery int query;cin>>query;while(query--)
#define benfero freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int ar[100005];
ll dp[100005];
int main(){
ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//benfero
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	memset(dp,10000,sizeof(dp));
	dp[1]=0;
	for(int i=2;i<=n;i++){
		for(int j=1;i-j>0&&j<=k;j++){
			dp[i]=min(dp[i],dp[i-j]+abs(ar[i]-ar[i-j]));
		}
	}
	cout<<dp[n];
}

Measured memory_bytes: 1408