N, K = list(map(int, input().split()))

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

dp = [1000000001 for i in range(N)]

dp[0] = 0

for i in range(N):

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

        if i+j <= N-1:

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



print((dp[N-1]))

N, K = list(map(int, input().split()))

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

dp = [10000000000]*(N+100)

dp[0] = 0

for i in range(N):

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

        if i + j <= N-1:

            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 = [1000000001 for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if i + j <= N - 1:
            dp[i + j] = min(dp[i] + abs(h[i + j] - h[i]), dp[i + j])
print((dp[N - 1]))

N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [10000000000] * (N + 100)
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if i + j <= N - 1:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print((dp[N - 1]))

-dp = [1000000001 for i in range(N)] +dp = [10000000000] * (N + 100) -            dp[i + j] = min(dp[i] + abs(h[i + j] - h[i]), dp[i + j]) +            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))