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

h = list(map(int,input().split()))

dp = [10**100]*n

dp[0] = 0

for i in range(1,n):

    for j in range(1,k+1):

        if i-j >= 0:

            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])

        else:

            break

print((dp[-1]))
n,k = list(map(int,input().split()))

h = list(map(int,input().split()))

inf = 10**12

dp = [inf]*n

dp[0] = 0

for i in range(n):

    for j in range(1,k+1):

        if i+j < n:

            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))

print((dp[-1]))
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [10**100] * n
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i])
        else:
            break
print((dp[-1]))

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10**12
dp = [inf] * n
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print((dp[-1]))

-dp = [10**100] * n +inf = 10**12 +dp = [inf] * n -for i in range(1, n): +for i in range(n): -        if i - j >= 0: -            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]) -        else: -            break +        if i + j < n: +            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))