import numpy as np



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

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



dp = np.zeros(N, dtype=int)

for i in range(1, N):

    dp[i] = min(dp[max(0,i-K):i]+abs(h[max(0,i-K):i]-h[i]))



print((dp[-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:

            break

        else:

            step = abs(h[i] - h[i-j])

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

 

print((dp[N-1]))
import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    dp[i] = min(dp[max(0, i - K) : i] + abs(h[max(0, i - K) : i] - h[i]))
print((dp[-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:
            break
        else:
            step = abs(h[i] - h[i - j])
            dp[i] = min(dp[i], dp[i - j] + step)
print((dp[N - 1]))

-import numpy as np - -h = np.array(list(map(int, input().split()))) -dp = np.zeros(N, dtype=int) +h = list(map(int, input().split())) +dp = [float("inf")] * N +dp[0] = 0 -    dp[i] = min(dp[max(0, i - K) : i] + abs(h[max(0, i - K) : i] - h[i])) -print((dp[-1])) +    for j in range(1, K + 1): +        if i - j < 0: +            break +        else: +            step = abs(h[i] - h[i - j]) +            dp[i] = min(dp[i], dp[i - j] + step) +print((dp[N - 1]))