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

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



dp = [float("inf") for _ in range(n)]



dp[0] = 0



for i in range(1,n):

    for j in range(max(0,i-k),i):

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



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

readline = sys.stdin.buffer.readline

def even(n): return 1 if n%2==0 else 0



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

lst1 = list(map(int,readline().split()))



dp = [10**10 for _ in range(n)]

dp[0] = 0

for i in range(1,n):

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

		if i-j < 0:

			break

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



print((dp[-1]))

n, k = list(map(int, input().split()))
lst1 = list(map(int, input().split()))
dp = [float("inf") for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(max(0, i - k), i):
        dp[i] = min(dp[i], dp[j] + abs(lst1[i] - lst1[j]))
print((dp[-1]))

import sys

readline = sys.stdin.buffer.readline


def even(n):
    return 1 if n % 2 == 0 else 0


n, k = list(map(int, readline().split()))
lst1 = list(map(int, readline().split()))
dp = [10**10 for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j < 0:
            break
        dp[i] = min(dp[i], dp[i - j] + abs(lst1[i - j] - lst1[i]))
print((dp[-1]))

-n, k = list(map(int, input().split())) -lst1 = list(map(int, input().split())) -dp = [float("inf") for _ in range(n)] +import sys + +readline = sys.stdin.buffer.readline + + +def even(n): +    return 1 if n % 2 == 0 else 0 + + +n, k = list(map(int, readline().split())) +lst1 = list(map(int, readline().split())) +dp = [10**10 for _ in range(n)] -    for j in range(max(0, i - k), i): -        dp[i] = min(dp[i], dp[j] + abs(lst1[i] - lst1[j])) +    for j in range(1, k + 1): +        if i - j < 0: +            break +        dp[i] = min(dp[i], dp[i - j] + abs(lst1[i - j] - lst1[i]))