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

H = [int(h) for h in input().split()]



dp = [0]*N



for i in range(1, N):

    j = i-1

    cost = 10**18

    while j >= max(0, i-K):

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

        j -= 1

    dp[i] = cost

    

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

H = [int(h) for h in input().split()]



dp = [10**12]*N

dp[0] = 0

for i in range(1, N):

    t = 1

    while t <= K and i-t >= 0:

        dp[i] = min(dp[i], dp[i-t]+abs(H[i]-H[i-t]))

        t += 1

        

print((dp[-1]))
N, K = list(map(int, input().split()))
H = [int(h) for h in input().split()]
dp = [0] * N
for i in range(1, N):
    j = i - 1
    cost = 10**18
    while j >= max(0, i - K):
        cost = min(cost, dp[j] + abs(H[i] - H[j]))
        j -= 1
    dp[i] = cost
print((dp[N - 1]))

N, K = list(map(int, input().split()))
H = [int(h) for h in input().split()]
dp = [10**12] * N
dp[0] = 0
for i in range(1, N):
    t = 1
    while t <= K and i - t >= 0:
        dp[i] = min(dp[i], dp[i - t] + abs(H[i] - H[i - t]))
        t += 1
print((dp[-1]))

-dp = [0] * N +dp = [10**12] * N +dp[0] = 0 -    j = i - 1 -    cost = 10**18 -    while j >= max(0, i - K): -        cost = min(cost, dp[j] + abs(H[i] - H[j])) -        j -= 1 -    dp[i] = cost -print((dp[N - 1])) +    t = 1 +    while t <= K and i - t >= 0: +        dp[i] = min(dp[i], dp[i - t] + abs(H[i] - H[i - t])) +        t += 1 +print((dp[-1]))