import numpy as np

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

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

dp=np.zeros(n,dtype="int32")

for i in range(1,n):

    start=0 if k>i else i-k

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

print((dp[-1]))
n,k=list(map(int,input().split()))

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

dp=[10**8]*n

dp[0]=0

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

for i in range(2,n):

    dp[i]=min([dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)])

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

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

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [10**8] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
print((dp[n - 1]))

-import numpy as np - -h = np.array(list(map(int, input().split()))) -dp = np.zeros(n, dtype="int32") -for i in range(1, n): -    start = 0 if k > i else i - k -    dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i])) -print((dp[-1])) +h = list(map(int, input().split())) +dp = [10**8] * n +dp[0] = 0 +dp[1] = abs(h[1] - h[0]) +for i in range(2, n): +    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)]) +print((dp[n - 1]))