import numpy as np



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

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



# dp = np.array([-1 for _ in range(N)])

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



dp[0] = 0



for i in range(1, N):

    start = max(0, i-K)

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



print((dp[-1]))

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

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

 

dp = [-1 for _ in range(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]))
import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))
# dp = np.array([-1 for _ in range(N)])
dp = np.zeros(N, dtype=int)
dp[0] = 0
for i in range(1, N):
    start = max(0, i - K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[-1]))

N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [-1 for _ in range(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]))

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