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(1,K+1):

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



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

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



ans = [float("inf")] * N

ans[0] = 0

for i in range(N-1):

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

        if i + j > N - 1:

            continue

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

print((ans[-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(1, K + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print((dp[-1]))

N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
ans = [float("inf")] * N
ans[0] = 0
for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j > N - 1:
            continue
        ans[i + j] = min(ans[i + j], ans[i] + abs(h[i] - h[i + j]))
print((ans[-1]))

-dp = [float("inf")] * N -dp[0] = 0 -dp[1] = abs(h[1] - h[0]) -for i in range(2, N): +ans = [float("inf")] * N +ans[0] = 0 +for i in range(N - 1): -        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])) -print((dp[-1])) +        if i + j > N - 1: +            continue +        ans[i + j] = min(ans[i + j], ans[i] + abs(h[i] - h[i + j])) +print((ans[-1]))