import sys

input = sys.stdin.readline

 

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

h = [0] + list(map(int,input().split()))

 

dp = [None for _ in range(N+1)]

dp[1] = 0

 

for i in range(2,N+1):

    scope = min(i-1,K)

    jump = [dp[i-x] + abs(h[i]-h[i-x]) for x in range(1,scope+1)]

    dp[i] = min(jump)

    

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

h = [0] + list(map(int,input().split()))



dp = [0] * (N+1)



for i in range(2,N+1):

    scope = min(i-1,K)

    jump = [dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,scope+1)]

    dp[i] = min(jump)



print((dp[N]))
import sys

input = sys.stdin.readline
N, K = list(map(int, input().split()))
h = [0] + list(map(int, input().split()))
dp = [None for _ in range(N + 1)]
dp[1] = 0
for i in range(2, N + 1):
    scope = min(i - 1, K)
    jump = [dp[i - x] + abs(h[i] - h[i - x]) for x in range(1, scope + 1)]
    dp[i] = min(jump)
print((dp[N]))

N, K = list(map(int, input().split()))
h = [0] + list(map(int, input().split()))
dp = [0] * (N + 1)
for i in range(2, N + 1):
    scope = min(i - 1, K)
    jump = [dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, scope + 1)]
    dp[i] = min(jump)
print((dp[N]))

-import sys - -input = sys.stdin.readline -dp = [None for _ in range(N + 1)] -dp[1] = 0 +dp = [0] * (N + 1) -    jump = [dp[i - x] + abs(h[i] - h[i - x]) for x in range(1, scope + 1)] +    jump = [dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, scope + 1)]