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

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

c=[0]*n

for i in range(1,n):

    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])

print((c[-1]))
import numpy as np

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

h=np.array(list(map(int,input().split()))+[0]*k)

dp = np.full(n+k, 10 ** 10, dtype=np.int64)

dp[0] = 0

for i in range(1,n):

    dp[i:i+k]=np.minimum(dp[i:i+k],np.abs(h[i:i+k]-h[i-1])+dp[i-1])

print((dp[n-1]))
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    c[i] = min(
        [
            cj + abs(h[i] - hj)
            for cj, hj in zip(c[max(0, i - k) : i], h[max(0, i - k) : i])
        ]
    )
print((c[-1]))

import numpy as np

n, k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())) + [0] * k)
dp = np.full(n + k, 10**10, dtype=np.int64)
dp[0] = 0
for i in range(1, n):
    dp[i : i + k] = np.minimum(
        dp[i : i + k], np.abs(h[i : i + k] - h[i - 1]) + dp[i - 1]
    )
print((dp[n - 1]))

+import numpy as np + -h = list(map(int, input().split())) -c = [0] * n +h = np.array(list(map(int, input().split())) + [0] * k) +dp = np.full(n + k, 10**10, dtype=np.int64) +dp[0] = 0 -    c[i] = min( -        [ -            cj + abs(h[i] - hj) -            for cj, hj in zip(c[max(0, i - k) : i], h[max(0, i - k) : i]) -        ] +    dp[i : i + k] = np.minimum( +        dp[i : i + k], np.abs(h[i : i + k] - h[i - 1]) + dp[i - 1] -print((c[-1])) +print((dp[n - 1]))