import numpy as np

N, K = (int(i) for i in input().split())  

h = np.array([int(i) for i in input().split()])

 

dp = np.empty(N, dtype='int')

 

for i in range(N):

  if i == 0:

    dp[i] = 0

  elif i - K < 0:

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

  else:

    dp[i] = np.min(np.abs(h[i] - h[i-K:i]) + dp[i-K:i])

 

print((dp[N-1]))


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

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



dp = [0]*n

dp[0] = 0

dp[1] = abs(h[0]-h[1])



for i in range(2,n):

     j = max(0,i-k)

     dp[i] = min([dp[l]+abs(h[i]-h[l]) for l in range(j,i)])



print((int(dp[n-1])))

import numpy as np

N, K = (int(i) for i in input().split())
h = np.array([int(i) for i in input().split()])
dp = np.empty(N, dtype="int")
for i in range(N):
    if i == 0:
        dp[i] = 0
    elif i - K < 0:
        dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i])
    else:
        dp[i] = np.min(np.abs(h[i] - h[i - K : i]) + dp[i - K : i])
print((dp[N - 1]))

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    j = max(0, i - k)
    dp[i] = min([dp[l] + abs(h[i] - h[l]) for l in range(j, i)])
print((int(dp[n - 1])))

-import numpy as np - -N, K = (int(i) for i in input().split()) -h = np.array([int(i) for i in input().split()]) -dp = np.empty(N, dtype="int") -for i in range(N): -    if i == 0: -        dp[i] = 0 -    elif i - K < 0: -        dp[i] = np.min(np.abs(h[i] - h[:i]) + dp[:i]) -    else: -        dp[i] = np.min(np.abs(h[i] - h[i - K : i]) + dp[i - K : i]) -print((dp[N - 1])) +n, k = list(map(int, input().split())) +h = list(map(int, input().split())) +dp = [0] * n +dp[0] = 0 +dp[1] = abs(h[0] - h[1]) +for i in range(2, n): +    j = max(0, i - k) +    dp[i] = min([dp[l] + abs(h[i] - h[l]) for l in range(j, i)]) +print((int(dp[n - 1])))