import sys

input = sys.stdin.readline



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

h = [int(x) for x in input().split()]

dp = [0] * N



for i, hi in enumerate(h):

    if i == 0:

        continue

    if i - K < 0:

        dp[i] = min(dpk + abs(hi-hk) for dpk, hk in zip(dp[:i], h[:i]))

    else:

        dp[i] = min(dpk + abs(hi-hk) for dpk, hk in zip(dp[i-K:i], h[i-K:i]))



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

h = [int(_) for _ in input().split()]

dp = [float('inf')]*(N)

dp[0] = 0

dp[1] = abs(h[1]-h[0])



for i in range(2, N):

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

        if i >= j:

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



print((dp[N-1]))
import sys

input = sys.stdin.readline
N, K = list(map(int, input().split()))
h = [int(x) for x in input().split()]
dp = [0] * N
for i, hi in enumerate(h):
    if i == 0:
        continue
    if i - K < 0:
        dp[i] = min(dpk + abs(hi - hk) for dpk, hk in zip(dp[:i], h[:i]))
    else:
        dp[i] = min(dpk + abs(hi - hk) for dpk, hk in zip(dp[i - K : i], h[i - K : i]))
print((dp[-1]))

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

-import sys - -input = sys.stdin.readline -h = [int(x) for x in input().split()] -dp = [0] * N -for i, hi in enumerate(h): -    if i == 0: -        continue -    if i - K < 0: -        dp[i] = min(dpk + abs(hi - hk) for dpk, hk in zip(dp[:i], h[:i])) -    else: -        dp[i] = min(dpk + abs(hi - hk) for dpk, hk in zip(dp[i - K : i], h[i - K : i])) -print((dp[-1])) +h = [int(_) for _ in input().split()] +dp = [float("inf")] * (N) +dp[0] = 0 +dp[1] = abs(h[1] - h[0]) +for i in range(2, N): +    for j in range(1, K + 1): +        if i >= j: +            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]) +print((dp[N - 1]))