#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>  
using namespace std;

#define ff 	 		first	
#define ss 	 		second
#define pb 	 		push_back
#define pf 	 		push_front
#define pob 		pop_back
#define pof 		pop_front
#define mp 	 		make_pair
#define ins 		insert
#define ll 	 		long long int
#define ld 	 		long double
#define ull 		unsigned long long
#define loop(i,n) 	for(ll i=0;i<n;i++)
#define loop1(i,n) 	for(ll i=1;i<=n;i++)
#define rev(i,n) 	for(ll i=n-1;i>=0;i--)
#define rev1(i,n) 	for(ll i=n;i>=1;i--)
#define test(t) 	int t;cin>>t;while(t--)
#define endl 		'\n'
#define all(c) 	 	(c).begin(), (c).end()
#define tr(c,it) 	for(auto it=(c).begin(); it!=(c).end(); it++)
#define rtr(c,it) 	for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define sz(c) 	 	(c).size()
// Define mod as per requirement
const ll MOD =1000000007;
//const ll MOD= 998244353; 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll; 
struct Order1{bool operator()(pll const& a,pll const& b)const{return (a.ss < b.ss || (a.ss == b.ss && a.ff < b.ff));}};
struct Order2{bool operator()(pll const& a,pll const& b)const{return (a.ff < b.ff || (a.ff == b.ff && a.ss < b.ss));}};
typedef priority_queue <ll> maxpq;// maximum priority_queue
typedef priority_queue <ll, vector<ll>, greater<ll> > minpq; //minimum priority_queue
typedef priority_queue <pll> maxpq_pair_f;// maximum priority_queue for pairs with maximum ff
typedef priority_queue <pll,vector<pll>, Order2 > max_pq_s; // maximum priority_queue for pairs with maximum ss
typedef priority_queue< pll, vector<pll>, greater<pll> > minpq_pair_f; //minimum priority_queue for pairs with the smallest ff
typedef priority_queue< pll, vector<pll>, Order1 > minpq_pair_s; //minimum priority_queue for pairs with the smallest ss

long long min(long long a,long long b){if(b<=a)return b;return a;}
long long max(long long a,long long b){if(a>=b)return a;return b;}
long long add(long long x, long long y){x += y;while(x >= MOD) x -= MOD;while(x < 0) x += MOD;return x;}
long long multiply(long long x, long long y){return (x * 1ll * y) % MOD;}
long long power(long long x, long long y){long long z = 1;while(y){if(y & 1) z = multiply(z, x);x = multiply(x, x);y >>= 1;}return z;}
long long modInverse(long long x){return power(x, MOD - 2);}
long long divide(long long x, long long y){return multiply(x, modInverse(y));}
long long gcd(long long a,long long b) { if(a == 0)return b;return gcd(b % a, a);}
long long lcm(long long a,long long b){long long val=max(a,b)/gcd(a,b);val*=min(a,b);return val;} 
const long long N=200050; // can be changed as per constraints
long long fact[N]; // array to store values of factorial
void cal_factorial(){fact[0] = 1;for(long long i = 1; i < N; i++)fact[i] = multiply(fact[i - 1], i);}// function to calculate factorial upto N
long long nCr(long long n, long long k){return divide(fact[n], multiply(fact[k], fact[n - k]));}
void BOOST(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
bool inc(long long x,long long y){return x<=y;}// for increasing order
bool dec(long long x,long long y){return x>=y;}// for decreasing order
// For union and intersection of vectors
vector<int>Intersection(vi &v1,vi&v2){vi v3;sort(all(v1));sort(all(v2));set_intersection(all(v1),all(v2),back_inserter(v3));return v3;}
vector<int>Union(vi &v1,vi&v2){vi v3;sort(all(v1));sort(all(v2));set_union(all(v1),all(v2),back_inserter(v3));return v3;}


int main(){
	BOOST();
	ll n;cin>>n;
	ll k;cin>>k;
	vector<ll>h(n+1);
	loop(i,n)cin>>h[i+1];
	vector<ll>dp(n+3,INT_MAX);
	dp[0]=0;
	dp[1]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(i+j<=n)
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
		}
	}
	cout<<dp[n]<<endl;

}


Measured memory_bytes: 1792