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

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



dp = [float('inf')] * n

dp[0] = 0

dp[1] = abs(h[1]-h[0])

for i in range(2,n):

    for j in range(k+1):

        if i - j < 0:

            continue

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

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

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



dp = [float('inf')] * n

dp[0]= 0



for i in range(n):

    for j in range(k+1):

        if i + j < n:

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



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

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

-dp[1] = abs(h[1] - h[0]) -for i in range(2, n): +for i in range(n): -        if i - j < 0: -            continue -        dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]) +        if i + j < n: +            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))