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

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



INF = 10 ** 9 + 1

dp = [INF] * N

dp[0] = 0



for i in range(1, N):

  dp[i] = min(pre + abs(h - H[i]) for pre,h in zip(dp[max(0,i - K):i],H[max(0,i - K):i]))



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

import numpy as np

H = np.array(input().split(), dtype = int)



INF = 10 ** 9 + 1

dp = np.full(N,INF,dtype = int)

dp[0] = 0



for i in range(1, N):

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



print((dp[-1]))
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
INF = 10**9 + 1
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(
        pre + abs(h - H[i])
        for pre, h in zip(dp[max(0, i - K) : i], H[max(0, i - K) : i])
    )
print((dp[-1]))

N, K = list(map(int, input().split()))
import numpy as np

H = np.array(input().split(), dtype=int)
INF = 10**9 + 1
dp = np.full(N, INF, dtype=int)
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[max(i - K, 0) : i] + abs(H[max(i - K, 0) : i] - H[i]))
print((dp[-1]))

-H = list(map(int, input().split())) +import numpy as np + +H = np.array(input().split(), dtype=int) -dp = [INF] * N +dp = np.full(N, INF, dtype=int) -    dp[i] = min( -        pre + abs(h - H[i]) -        for pre, h in zip(dp[max(0, i - K) : i], H[max(0, i - K) : i]) -    ) +    dp[i] = min(dp[max(i - K, 0) : i] + abs(H[max(i - K, 0) : i] - H[i]))