import numpy as np



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

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

dp = np.ones(N, dtype=np.int64) * (2 ** 62)

dp[0] = 0

for i in range(1, N):

    cost = np.abs(H[i - 1] - H[i : i + K])

    np.minimum(dp[i : i + K], dp[i - 1] + cost, out=dp[i : i + K])

print((dp[-1]))

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

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

dp = [1 << 62] * N

dp[0] = 0

for i in range(1, N):

    for j in range(K):

        if i + j < N:

            cost = abs(H[i - 1] - H[i + j])

            dp[i + j] = min(dp[i + j], dp[i - 1] + cost)

print((dp[-1]))

import numpy as np

N, K = list(map(int, input().split()))
H = np.array(list(map(int, input().split())), dtype=np.int64)
dp = np.ones(N, dtype=np.int64) * (2**62)
dp[0] = 0
for i in range(1, N):
    cost = np.abs(H[i - 1] - H[i : i + K])
    np.minimum(dp[i : i + K], dp[i - 1] + cost, out=dp[i : i + K])
print((dp[-1]))

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
dp = [1 << 62] * N
dp[0] = 0
for i in range(1, N):
    for j in range(K):
        if i + j < N:
            cost = abs(H[i - 1] - H[i + j])
            dp[i + j] = min(dp[i + j], dp[i - 1] + cost)
print((dp[-1]))

-import numpy as np - -H = np.array(list(map(int, input().split())), dtype=np.int64) -dp = np.ones(N, dtype=np.int64) * (2**62) +H = list(map(int, input().split())) +dp = [1 << 62] * N -    cost = np.abs(H[i - 1] - H[i : i + K]) -    np.minimum(dp[i : i + K], dp[i - 1] + cost, out=dp[i : i + K]) +    for j in range(K): +        if i + j < N: +            cost = abs(H[i - 1] - H[i + j]) +            dp[i + j] = min(dp[i + j], dp[i - 1] + cost)