import numpy as np



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

H = np.array(list(map(int, input().split())) + [0] * K, dtype=np.int64)



table = np.full(N + K, 10 ** 10, dtype=np.int64)

table[0] = 0



for i in range(1, N):

    table[i:i + K] = np.minimum(table[i:i + K], np.abs(H[i:i + K] - H[i - 1]) + table[i - 1])



print((table[N - 1]))

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

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



table = [0] * N

for i in range(1, N):

    table[i] = min(abs(H[i] - H[j]) + table[j] for j in range(max(0, i - K), i))



print((table[N-1]))

import numpy as np

N, K = list(map(int, input().split()))
H = np.array(list(map(int, input().split())) + [0] * K, dtype=np.int64)
table = np.full(N + K, 10**10, dtype=np.int64)
table[0] = 0
for i in range(1, N):
    table[i : i + K] = np.minimum(
        table[i : i + K], np.abs(H[i : i + K] - H[i - 1]) + table[i - 1]
    )
print((table[N - 1]))

N, K = list(map(int, input().split()))
H = tuple(map(int, input().split()))
table = [0] * N
for i in range(1, N):
    table[i] = min(abs(H[i] - H[j]) + table[j] for j in range(max(0, i - K), i))
print((table[N - 1]))

-import numpy as np - -H = np.array(list(map(int, input().split())) + [0] * K, dtype=np.int64) -table = np.full(N + K, 10**10, dtype=np.int64) -table[0] = 0 +H = tuple(map(int, input().split())) +table = [0] * N -    table[i : i + K] = np.minimum( -        table[i : i + K], np.abs(H[i : i + K] - H[i - 1]) + table[i - 1] -    ) +    table[i] = min(abs(H[i] - H[j]) + table[j] for j in range(max(0, i - K), i))