#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <iterator>
#define foor(i,n) for (int i=0;i<n;i++)
#define faor(i,m,n) for (int i=m;i<n;i++)
#define fastio std::ios::sync_with_stdio(false);
#define inf while(true)
#define lowcase(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define uppcase(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define bs(n) bitset <n>
#define vec vector
#define GE_PI 3.14159265359
#define pii pair <s64,s64>
typedef unsigned char u8;
typedef char s8;
typedef short int s16;
typedef long int s32;
typedef long long int s64;
typedef unsigned short int u16;
typedef unsigned long int u32;
typedef unsigned long long int u64;
typedef float f32;
typedef double  f64;
typedef long double f128;
typedef bool s1;

using namespace std;



s64 phi(s64 n);
s64 phi_strictlyless(s64 n);
s64 gray (s64 n);
s64 rev_gray (s64 g);
s64 factmod(s64 n, s64 p);
pair<s64, s64> fib (s64 n);
void yes(void);
void no(void);
bool isPrime(s64 );

s64 LCM(s64 ,s64 );
s64 rangesum (s64 ,s64);
u64 fact(s64 );
 u64 permut(s64 , s64 );
u64 combin( u64 n, u64 k );
//s64 reversenum (s64);
//s64 digit_count(s64 );
f64 powers(f64 ,s32 );
//s64 power10 (s64 );
s64 strongpowers (s64,s64 , s64 );
//s64 binary_converter (s64 );
//void prob(u32 );
s64 divisibility (s64 a,s64 b,s64 c);
s64 divisibilitycount(s64 a,s64 b,s64 c);
f64 GE_distance(s64 ,s64,s64 ,s64 );
s16 dx[4]={0,0,1,-1};
s16 dy[4]={1,-1,0,0};


s16 dxx[8]={0,0,1,-1,1,-1,1,-1};
s16 dyy[8]={1,-1,0,0,1,-1,-1,1};


//complex
#define preimag const   complex<double> im(0.0,1.0);
#define dzero .00000001
#define Piont(x,a,b) complex <double> x(a,b)
#define xval real()
#define yval real()
#define vect(x,a,b)  x=b-a
#define veclength(x)  hypot((x.real()),(x.imag()))
#define vecnormalize(x) x/veclength(x)
#define vecdp(x,y) ((conj(x)*y).real())
#define vecdpdp(x,y) ((conj(vecnormalize(x))*vecnormalize(y)).real())
#define veccp(x,y) ((conj(x)*y).imag())
#define veccpcp(x,y) ((conj(vecnormalize(x))*vecnormalize(y)).imag())
#define veclengtgsqr(x) vecdp(x,x)
#define vecsame(x,y) abs(vecdp(x,ymkmmmmmmmmmm))<dzero
#define vecrotate(x,angle) x*exp(im * GE_PI*(double)angle/180.0)
#define vecreflect(x,y) conj(x/y)*y
//#define vecrotateA(x,angle,y) vecrotate(vect((complex<double> z(0,0)),y,x),angle)+y

s64 combino(s64 a,s64 b);












int main()
{


    s64 a,b,c,d;
    cin>>a>>b;
    s64 x[100100],y[100100];
    foor(i,a)
    y[i]=999999999999;
    y[0]=0;
  //  cin>>a>>b;
    foor(i,a)
    cin>>x[i];


    foor(i,a)
    faor(j,1,min(b+1,a-i))
    {
        y[i+j]=min(y[i+j],y[i]+abs(x[i+j]-x[i]));
    }
    cout<<y[a-1];
}
















s64 combino(s64 a,s64 b)
{
    if(a<b)
        return 0;
    else
        return combin(a,b);
}



s64 factmod(s64 n, s64 p) {
    s64 res = 1;
    while (n > 1) {
        res = (res * ((n/p) % 2 ?  p-1 : 1)) % p;
        for (s64 i = 2; i <= n%p; ++i)
            res = (res * i) % p;
        n /= p;
    }
    return res % p;
}


s64 gray (s64 n) {
    return n ^ (n >> 1);
}

s64 rev_gray (s64 g) {
  s64 n = 0;
  for (; g; g >>= 1)
    n ^= g;
  return n;
}



    s64 phi(s64 n) {
    s64 result = n;
    for (s64 i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
s64 phi_strictlyless(s64 n)
{
    if(n==1)
        return 0;
    else
        return phi(n);
}

f64 GE_distance(s64 a,s64 b,s64 c,s64 d)
{
    return sqrt((double)((c-a)*(c-a)+(d-b)*(d-b)));
}


s64 divisibility (s64 a,s64 b,s64 c)
{
    //sorted

    s64 k=0;

    if(a%c!=0)
 {k=a%c;
 a+=(c-k);}

 b-=b%c;
 if(b<a)
 {

     return 0;
 }


    return((a+b)*(((b-a)/c)+1))/2;
}

s64 divisibilitycount(s64 a,s64 b,s64 c)
{


    return abs(a/c-(b-1)/c);
}
u64 fact(s64 n)
{
    if(n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
u64 permut(s64 n,s64 m)
{
    if(n >n-m )
        return n * permut(n - 1,m-1);
    else
        return 1;
}
u64 combin( u64 n, u64 k )
{
    u64 res = 1;


    if ( k > n - k )
        k = n - k;


    for (u64 i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;


    }
 s64 rangesum (s64 a ,s64 b)
 {if(b>a)
 {
     b+=a;
     a=b-a;
     b=b-a;
 }
     return(a-b+1)*(a+b)/2;
 }
bool isPrime(s64 n)
 {

     if (n <= 1)  return false;
     if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

     for (s64 i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
     return true;
 }

s64 LCM(s64 a,s64 b)
{
    return (a/__gcd(a,b))*b;
}
s64 digit_count (s64 a)
{
    s32 x=0;
    while(a!=0)
    {a/=10;
    x++;}
    return x;
}


f64 powers(f64 a,s32 b)
{
    f64 x=1;
    foor(i,b)
    x*=a;

    return x;
}
s64 strongpowers (s64 b,s64 p , s64 m)
{
  s64  largepowervar =1;
if(p==0)
    return 1;
while(p>1)
{
    if(p&1)

        {largepowervar = (largepowervar*b)%m;p--;}
if(p){
        b=(b*b)%m;    p/=2;}

}
   return (b*largepowervar)%m;

}
s64 power10 (s64 b)
{
    return powers(10,b);
}
s64 reversenum (s64 a)
{s64 b=0;


s32 c=digit_count(a);
foor(i,c)
{
    b+=((a%10)*power10(c-i-1));
    a/=10;
 }
   return b;

}
s64 binary_converter (s64 a)
{
    s64 c=0;s64 i=0;
    while(a!=0)
    {
        c+=((a%2)*power10(i));
        a/=2;
        i++;
    }
    return c;
}

void yes(void)
{cout<<"YES";}

void no(void)
{cout<<"NO";
}


Measured memory_bytes: 1792