#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb push_back
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD= 1e9+7 ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

ll sum(ll k){
	if(k<0)
		return 0;
	return (k * (k+1))/2;
}

struct FenwickTree
{
	int N;
	vector<int> tree;
 
	void init(int n)
	{
		N = n;
		tree.assign(n + 1, 0);
	}
 
	void update(int idx, int val)
	{
		while (idx <= N)
		{
			tree[idx] += val;
			idx += idx & -idx;
		}
	}
 
	void updateMax(int idx, int val)
	{
		while (idx <= N)
		{
			tree[idx] = max(tree[idx], val);
			idx += idx & -idx;
		}
	}
 
	int pref(int idx)
	{
		int ans = 0;
		while (idx > 0)
		{
			ans += tree[idx];
			idx -= idx & -idx;
		}
		return ans;
	}
 
	int rsum(int l, int r)
	{
		return pref(r) - pref(l - 1);
	}
 
	int prefMax(int idx)
	{
		int ans = -2e9;
		while (idx > 0)
		{
			ans = max(ans, tree[idx]);
			idx -= idx & -idx;
		}
		return ans;
	}
};
//~ const int MAXN = 1e6+10;
//~ std::vector <int> prime;
//~ bool is_composite[MAXN];

//~ void sieve (int n) {
	//~ std::fill (is_composite, is_composite + n, false);
	//~ for (int i = 2; i < n; ++i) {
		//~ if (!is_composite[i]) prime.push_back (i);
		//~ for (int j = 0; j < (int)prime.size () && i * prime[j] < n; ++j) {
			//~ is_composite[i * prime[j]] = true;
			//~ if (i % prime[j] == 0) break;
		//~ }
	//~ }
//~ }

const int INF = 1e9+10;

int main()
{
    fast;
    
    ll t;
    t = 1;
    //~ cin>>t;
    
    while(t--){
			int n,k;
			cin>>n>>k;
			vector<int>v(n);
			for(auto &it: v){
				cin>>it;
			}
			
			vector<int>dp(n, INF);
			dp[0] = 0;
			for(int i=0;i<n;i++){
				for(int j = i+1; j<=i+k;j++){
					if(j<n){
						dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j]));
					}
				}
			}
			cout<<dp[n-1];
	}
    return 0;
}


Measured memory_bytes: 3932