import numpy as np

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

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

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



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

k = np.array([i for i in range(1, K+1)])



for n in range(1, N):

    start = max(n-K, 0)

    #if n < K:

    #   dp[n] = np.amin(dp[start] + np.abs(H[n]-H[start]))

    #else:

    #   dp[n] = np.min(dp[n - k] + np.abs(H[n] - H[n - k]))

    dp[n] = np.min(dp[start:n] + np.abs(H[n]-H[start:n]))



print((dp[N-1]))
N, K = list(map(int, input().split()))

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



INF = 10000000000

dp = [INF]*N

dp[0] = 0



for i in range(N):

    for k in range(1, K+1):

        if i + k < N:

            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))



print((dp[N-1]))
import numpy as np

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

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

-import numpy as np - -# H = np.array([int(h) for h in input().split()]) -H = np.array(list(map(int, input().split()))) -dp = np.zeros(N, dtype=int) -k = np.array([i for i in range(1, K + 1)]) -for n in range(1, N): -    start = max(n - K, 0) -    # if n < K: -    #   dp[n] = np.amin(dp[start] + np.abs(H[n]-H[start])) -    # else: -    #   dp[n] = np.min(dp[n - k] + np.abs(H[n] - H[n - k])) -    dp[n] = np.min(dp[start:n] + np.abs(H[n] - H[start:n])) +H = list(map(int, input().split())) +INF = 10000000000 +dp = [INF] * N +dp[0] = 0 +for i in range(N): +    for k in range(1, K + 1): +        if i + k < N: +            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))