import numpy as np



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

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

dp = np.full(N,10**10)

dp[0] = 0

for i in range(1,N):

    start = max(0,i-K)

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

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

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

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



INF = float('inf')

dp = [INF] * (N)

dp[0] = 0



for i in range(1,N):

    cost = INF

    for j in range(max(0,i-K),i):

        # print(h[j],':',h[i])

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

    # print(dp)

print((dp[-1]))

import numpy as np

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

N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
INF = float("inf")
dp = [INF] * (N)
dp[0] = 0
for i in range(1, N):
    cost = INF
    for j in range(max(0, i - K), i):
        # print(h[j],':',h[i])
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]))
    # print(dp)
print((dp[-1]))

-import numpy as np - -h = np.array(list(map(int, input().split()))) -dp = np.full(N, 10**10) +h = list(map(int, input().split())) +INF = float("inf") +dp = [INF] * (N) -    start = max(0, i - K) -    dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i])) -print((int(dp[-1]))) +    cost = INF +    for j in range(max(0, i - K), i): +        # print(h[j],':',h[i]) +        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i])) +    # print(dp) +print((dp[-1]))