/*#include <bits/stdc++.h>
#define cross(a,b) (conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define ld long double
#define ll long long
#define vec(a,b) (b-a)
#define pi acos(-1)
//#define x real()
//#define y imag()


using namespace std;
typedef complex <ld> point;
typedef vector<point> polygon;
typedef tuple<int,int,int> line; // represents a b c of line

vector <ll> v;
//vector <ll> vc;

//ll mod = 1e9 +7;
//ll fact[1000005], inv[1000005];
//int p;


bool prime(ll n)
{
   if(n==1)
    return false;
   for(int i=2; i<=sqrt(n); ++i)
   {
       if(n%i==0)
       {
           return false;
       }
   }
   return true;
}

/*unsigned long long fp(ll x, ll y)
{
    if(y==0)
    {
        return 1;
    }
    ll z = fp(x,(y/2));

    if(y%2==0)
    {
        return (z*z)%p;
    }
    else
        return (((z*z)%p)*(x%p))%p;
}*/
/*unsigned long long fp(ll x, ll y)
{
    if(y==0)
    {
        return 1;
    }
    ll z = fp(x,(y/2));

    if(y%2==0)
    {
        return (z*z)%mod;
    }
    else
        return (((z*z)%mod)*(x%mod))%mod;
}
void pre()
{
  fact[0]=inv[0]=1;
  for(int i=1; i<=1000005; ++i)
  {
      fact[i]=(fact[i-1]*i)%mod;
      inv[i]=fp(fact[i], mod-2);
  }
}
unsigned ll ncr(int n, int r)
{
    return (((fact[n]*inv[n-r])%mod) * inv[r])%mod;
}*/

/*int main()
{
    //pre();
    int n, ans=0;
    ll c;
    cin >> n;
    for(int k=1; k<=n; ++k)
    {
        c=0;
        bool arr[30005]={false};
        if(prime(k))
            continue;
        for(ll i=1; i*i<=k; ++i)
        {
            if(k%i==0 && prime(i) && arr[i]==false)
            {
                c++;
                arr[i]=true;
            }
            if(k%i==0 && prime(k/i) && arr[k/i]==false)
            {
                    c++;
                    arr[k/i]=true;
            }
        }
        if(c==2)
            ans++;
    }
    cout << ans << endl;*/
/*cin >>p;
int cnt=0;
bool ch=1;
for(int i=1; i<p; ++i)
{
    ch=1;
    for(int j=1; j<=p-2; ++j)
    {
            if(((fp(i,j)-1)+p)%p==0)
            {
                ch=0;
            }
            if( ((fp(i,p-1)-1)+p)%p!=0)
            {
                ch=0;
            }
            if(!ch)
            {
                break;
            }
    }
    if(ch)
        cnt++;
}
cout << cnt << endl;*/
//return 0;
//}

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int n, x, arr[100005], ans[100005], h[100005];
int solve(int idx)
{
    if(idx>n-1)
        return 2e9;
    if(idx==n-1)
        return 0;
    if(arr[idx]!=-1)
        return arr[idx];
    int ans=2e9;
    for(int i=idx+1; i<=idx+x; ++i)
    {
        if(i<=n-1){
           ans=min(ans,abs(h[i]-h[idx])+solve(i));
        }
    }
    arr[idx]=ans;
    return ans;
}
//ll ans[N];
//int arr[N][3];
// vector< vector<ll> > v(N);
int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/
    cin >> n >> x;
    for(int i=0; i<n; ++i)
    {
        cin >> h[i];
    }
    memset(arr, -1, sizeof arr);
    cout << solve(0);
    /*int sum, n;
    cin >> sum >> n;
    int arr[n];
    for(int i=0; i<n; ++i)
    {
        cin >> arr[i];
    }
    for(int i=0; i<n; ++i)
    {
        ans[i][0]=1;
    }
    for(int i=0; i<n; ++i)
    {
        for(int j=1; j<=sum; ++j)
        {
            if(i)
            {
                ans[i][j]=ans[i-1][j];
            }
            if(j-arr[i]>=0)
            {
                ans[i][j]+=ans[i][j-arr[i]];
            }
        }
    }
    cout << ans[n-1][sum];*/
    return 0;
}





Measured memory_bytes: 5760