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):

  s = max(i-K,0)

  dp[i] = np.min(dp[s:i]+np.abs(H[s:i]-H[i]))



print((dp[-1]))

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

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



dp = [0]



for i in range(1,N):

  h = H[i]

  dp.append(min(dp[-j-1]+abs(h-H[i-j-1]) for j in range(min(i,K))))



print((dp[-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):
    s = max(i - K, 0)
    dp[i] = np.min(dp[s:i] + np.abs(H[s:i] - H[i]))
print((dp[-1]))

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