import sys

input = sys.stdin.readline



import numpy as np



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

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



dp = np.zeros(N, dtype=int)

h = np.array(h)



for i in range(1, N):

  start = max(0, i-K)

  dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))

print((dp[N-1]))    
import numpy as np

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

h = np.array(input().split(), dtype='int32')

dp = np.zeros(N, dtype='int32')

 

for i in range(1, N):

  start = 0 if i < K else i-K

  dp[i] = np.min(dp[start:i] + np.abs(h[i]-h[start:i]))

 

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

input = sys.stdin.readline
import numpy as np

N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = np.zeros(N, dtype=int)
h = np.array(h)
for i in range(1, N):
    start = max(0, i - K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[N - 1]))

import numpy as np

N, K = list(map(int, input().split()))
h = np.array(input().split(), dtype="int32")
dp = np.zeros(N, dtype="int32")
for i in range(1, N):
    start = 0 if i < K else i - K
    dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i]))
print((dp[-1]))

-import sys - -input = sys.stdin.readline -h = list(map(int, input().split())) -dp = np.zeros(N, dtype=int) -h = np.array(h) +h = np.array(input().split(), dtype="int32") +dp = np.zeros(N, dtype="int32") -    start = max(0, i - K) -    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i])) -print((dp[N - 1])) +    start = 0 if i < K else i - K +    dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i])) +print((dp[-1]))