import math

n,k=list(map(int,input().split()))

a=[int(i) for i in input().split()]

b=[0]*n

b[n-2]=abs(a[n-1]-a[n-2])

for i in range(n-3,-1,-1):

    c=[]

    for j in range(i+1,min(n,i+k+1)):

        c.append(abs(a[j]-a[i])+b[j])

    b[i]=min(c)

print((b[0]))
n,k=list(map(int,input().split()))

a=[int(i) for i in input().split()]

b=[0]*n

b[n-2]=abs(a[n-1]-a[n-2])

for i in range(n-3,-1,-1):

    mini=1000000000000000

    for j in range(i+1,min(n,i+k+1)):

        x=abs(a[j]-a[i])+b[j]

        mini=min(mini,x)

    b[i]=mini

print((b[0]))
import math

n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [0] * n
b[n - 2] = abs(a[n - 1] - a[n - 2])
for i in range(n - 3, -1, -1):
    c = []
    for j in range(i + 1, min(n, i + k + 1)):
        c.append(abs(a[j] - a[i]) + b[j])
    b[i] = min(c)
print((b[0]))

n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [0] * n
b[n - 2] = abs(a[n - 1] - a[n - 2])
for i in range(n - 3, -1, -1):
    mini = 1000000000000000
    for j in range(i + 1, min(n, i + k + 1)):
        x = abs(a[j] - a[i]) + b[j]
        mini = min(mini, x)
    b[i] = mini
print((b[0]))

-import math - -    c = [] +    mini = 1000000000000000 -        c.append(abs(a[j] - a[i]) + b[j]) -    b[i] = min(c) +        x = abs(a[j] - a[i]) + b[j] +        mini = min(mini, x) +    b[i] = mini