import sys



stdin = sys.stdin



mod = 1000000007

inf = 1 << 60



ni = lambda: int(ns())

na = lambda: list(map(int, stdin.readline().split()))

ns = lambda: stdin.readline().rstrip()

nas = lambda: stdin.readline().split()



n, k = na()

h = na()



dp = [inf] * n

dp[0] = 0

for i in range(n):

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

        if i + j < n:

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



print((dp[n - 1]))

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



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



INF = 1e12



dp = [INF] * n



dp[0] = 0

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



for i in range(2,n):

    pulo = 0

    for j in range(i-1,-1,-1):

        pulo += 1

        if pulo > k:

            break

        else:

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





print((dp[n-1]))

import sys

stdin = sys.stdin
mod = 1000000007
inf = 1 << 60
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()
n, k = na()
h = na()
dp = [inf] * n
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print((dp[n - 1]))

n, k = list(map(int, input().split()))
pedras = list(map(int, input().split()))
INF = 1e12
dp = [INF] * n
dp[0] = 0
dp[1] = abs(pedras[1] - pedras[0])
for i in range(2, n):
    pulo = 0
    for j in range(i - 1, -1, -1):
        pulo += 1
        if pulo > k:
            break
        else:
            dp[i] = min(dp[i], dp[j] + abs(pedras[i] - pedras[j]))
print((dp[n - 1]))

-import sys - -stdin = sys.stdin -mod = 1000000007 -inf = 1 << 60 -ni = lambda: int(ns()) -na = lambda: list(map(int, stdin.readline().split())) -ns = lambda: stdin.readline().rstrip() -nas = lambda: stdin.readline().split() -n, k = na() -h = na() -dp = [inf] * n +n, k = list(map(int, input().split())) +pedras = list(map(int, input().split())) +INF = 1e12 +dp = [INF] * n -for i in range(n): -    for j in range(1, k + 1): -        if i + j < n: -            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j])) +dp[1] = abs(pedras[1] - pedras[0]) +for i in range(2, n): +    pulo = 0 +    for j in range(i - 1, -1, -1): +        pulo += 1 +        if pulo > k: +            break +        else: +            dp[i] = min(dp[i], dp[j] + abs(pedras[i] - pedras[j]))