import sys

n, K = list(map(int, sys.stdin.readline().split()))

H = list(map(int, sys.stdin.readline().split()))



p = [float('inf') for _ in range(n)]

p[0] = 0

for i in range(1, n):

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

        if i-k >=0:

            tmp = abs(H[i]-H[i-k]) + p[i-k]

            if p[i] > tmp:

                p[i] = tmp



print((p[-1]))
#EDP-B

import sys

n, K = list(map(int, sys.stdin.readline().split()))

H = list(map(int, sys.stdin.readline().split()))

dp = [0 for i in range(n)]

#初期条件

for i in range(1, n):

    dp[i] = abs(H[i]-H[i-1]) + dp[i-1]

#print(dp)

for i in range(2, n):

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

        if i-k>=0:

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

            #print(dp, i, k)



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

n, K = list(map(int, sys.stdin.readline().split()))
H = list(map(int, sys.stdin.readline().split()))
p = [float("inf") for _ in range(n)]
p[0] = 0
for i in range(1, n):
    for k in range(1, K + 1):
        if i - k >= 0:
            tmp = abs(H[i] - H[i - k]) + p[i - k]
            if p[i] > tmp:
                p[i] = tmp
print((p[-1]))

# EDP-B
import sys

n, K = list(map(int, sys.stdin.readline().split()))
H = list(map(int, sys.stdin.readline().split()))
dp = [0 for i in range(n)]
# 初期条件
for i in range(1, n):
    dp[i] = abs(H[i] - H[i - 1]) + dp[i - 1]
# print(dp)
for i in range(2, n):
    for k in range(1, K + 1):
        if i - k >= 0:
            dp[i] = min(dp[i], abs(H[i] - H[i - k]) + dp[i - k])
            # print(dp, i, k)
print((dp[-1]))

+# EDP-B -p = [float("inf") for _ in range(n)] -p[0] = 0 +dp = [0 for i in range(n)] +# 初期条件 +    dp[i] = abs(H[i] - H[i - 1]) + dp[i - 1] +# print(dp) +for i in range(2, n): -            tmp = abs(H[i] - H[i - k]) + p[i - k] -            if p[i] > tmp: -                p[i] = tmp -print((p[-1])) +            dp[i] = min(dp[i], abs(H[i] - H[i - k]) + dp[i - k]) +            # print(dp, i, k) +print((dp[-1]))