inf = float('inf')



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

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



dp = [inf] * n

dp[0] = 0



for i in range(1, n):

    dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, k + 1) if i - j >= 0)



print((dp[n - 1]))

inf = float('inf')



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

h = list(map(int, input().split())) + [inf] * k



dp = [inf] * (n + k)

dp[0] = 0



# 配る

for i in range(n - 1):

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

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

print((dp[n - 1]))

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

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

-h = list(map(int, input().split())) -dp = [inf] * n +h = list(map(int, input().split())) + [inf] * k +dp = [inf] * (n + k) -for i in range(1, n): -    dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, k + 1) if i - j >= 0) +# 配る +for i in range(n - 1): +    for j in range(1, k + 1): +        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))