INF = float('inf')

dp = [INF] * (10**5 + 10)

dp[0] = 0

h = [0] * (10 ** 4)

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

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

for i in range(1, N+1):

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

        if i - k >= 0:

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

print((dp[N-1]))

INF = float('inf')

dp = [INF] * (10**5 + 10)

dp[0] = 0

h = [0] * (10 ** 4)

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

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

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]))

        else:

            break

print((dp[N-1]))
INF = float("inf")
dp = [INF] * (10**5 + 10)
dp[0] = 0
h = [0] * (10**4)
N, K = list(map(int, input().split()))
h = list(map(int, input().split())) + h
for i in range(1, N + 1):
    for k in range(1, K + 1):
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i - k] + abs(h[i] - h[i - k]))
print((dp[N - 1]))

INF = float("inf")
dp = [INF] * (10**5 + 10)
dp[0] = 0
h = [0] * (10**4)
N, K = list(map(int, input().split()))
h = list(map(int, input().split())) + h
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]))
        else:
            break
print((dp[N - 1]))

-for i in range(1, N + 1): +for i in range(N): -        if i - k >= 0: -            dp[i] = min(dp[i], dp[i - k] + abs(h[i] - h[i - k])) +        if i + k < N: +            dp[i + k] = min(dp[i + k], dp[i] + abs(h[i] - h[i + k])) +        else: +            break