n, k = list(map(int, input().split()))

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



dp = [1 << 30] * n

dp[0] = 0

for i in range(1, n):

    mn = 1 << 30

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

        if i - j < 0:

            continue

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

    dp[i] = mn



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

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



def chmin(a, b):

    if a > b: return b

    else: return a



dp = [float('inf')] * (n + k)

dp[0] = 0

for i in range(n):

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

        if i + j < n:

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

print((dp[n - 1]))
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [1 << 30] * n
dp[0] = 0
for i in range(1, n):
    mn = 1 << 30
    for j in range(1, k + 1):
        if i - j < 0:
            continue
        mn = min(mn, dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = mn
print((dp[-1]))

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


def chmin(a, b):
    if a > b:
        return b
    else:
        return a


dp = [float("inf")] * (n + k)
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print((dp[n - 1]))

-dp = [1 << 30] * n + + +def chmin(a, b): +    if a > b: +        return b +    else: +        return a + + +dp = [float("inf")] * (n + k) -for i in range(1, n): -    mn = 1 << 30 +for i in range(n): -        if i - j < 0: -            continue -        mn = min(mn, dp[i - j] + abs(h[i] - h[i - j])) -    dp[i] = mn -print((dp[-1])) +        if i + j < n: +            dp[i + j] = chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j])) +print((dp[n - 1]))