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

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

dp = [float("inf") for _ in range(n)]

dp[0] = 0



for i in range(n-1):

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

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



print((dp[n-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(1, n):

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

        if i-j >= 0:

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

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

-dp = [float("inf") for _ in range(n)] +dp = [float("inf")] * n -for i in range(n - 1): -    for j in range(1, min(k + 1, n - i)): -        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) +for i in range(1, n): +    for j in range(1, k + 1): +        if i - j >= 0: +            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))